Hi All,
Im having trouble getting a crob job to run.
What i have so far is
/home/ mysqldump -h -u root -ppassword database name | gzip > /home/echou/
any assistance would be appreciated
Hi All,
Im having trouble getting a crob job to run.
What i have so far is
/home/ mysqldump -h -u root -ppassword database name | gzip > /home/echou/
any assistance would be appreciated
Testing the command interactively (as suggested) is the right first step — that proves the dump works outside cron. marked the original problem resolved, but the checklist and safe workflow below will help avoid intermittent failures and security issues when the job runs unattended.
Common gotchas to check first:
crontab(5) for details (crontab manual). /var/log/cron or /var/log/syslog depending on distro; see the distro cron HOWTO for guidance: CronHowto). Safer dumps and security tips:
~/.my.cnf or a --defaults-extra-file) with permissions 600. MySQL documents option files and client behavior here: MySQL option files. --single-transaction to avoid long locks (see the mysqldump docs: mysqldump).Put the dump in a small script with absolute paths, log its output, and call that script from cron. Example skeleton:
#!/bin/sh
set -e
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
BACKUP_DIR=/root/backups
TIMESTAMP=$(date +%F-%H%M)
mkdir -p "$BACKUP_DIR"
/usr/bin/mysqldump --defaults-extra-file=/root/.my.cnf my_database | /bin/gzip > "$BACKUP_DIR/my_database-$TIMESTAMP.sql.gz" Then call it from cron (example, daily at 02:00):
0 2 * * * /root/bin/mysql-backup.sh >> /var/log/mysql-backup.log 2>&1 If a scheduled job still fails, capture the script output, inspect cron logs, and confirm the cron service is running.
Jump to Post— nonshatter 26Does that command run in your terminal? If it does then all you need to do is to to edit crontab and add the format to schedule the backup. How often do you want to run the command?
Does that command run in your terminal? If it does then all you need to do is to to edit crontab and add the format to schedule the backup. How often do you want to run the command?
See here for the format to use for scheduling tasks in crontab
sorted thank you
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.