how can I see if my backups is saved after the minute assigned? how can I test it if it's ok?
You have a couple of options here:
- Check the modification date of the file to see if it's being updated:
ls -l /var/backups/your-file.sql
- If you haven't quite migrated over to systemd yet, cron should be logging to
/var/log/syslog, in which case you can do something like this and check the timestamps:
cat /var/log/syslog | grep -i cron
- If you are on systemd though, you'll need to use this command:
sudo systemctl status cron
And look for something along the lines of this for your user:
Jun 28 17:44:01 openSUSE cron: pam_unix(crond:session): session opened for user billy by (uid=0)
Alternatively, you could put that command into a script that logs the outcome for you:
#!/bin/bash # It's good practice to include the full path to the executable when calling it in a script, especially from cron DATE=/usr/bin/date MYSQLDUMP=/usr/bin/mysqldump # Run your backup command here $MYSQLDUMP -u user -p password database > /var/backups/backup.sql # Then check to make sure it executed successfully if [[ $? -eq 0 ]]; then echo "$DATE - Backup saved" else echo "$DATE - Backup failed" fi
Save that as a file called say
db-backup.sh, give it execute permissions, and then set that as the cron job instead.Just remember to use the full path to the script since cron may have a different PATH than you do.
You can check for your logs, you can see if cron job executes:
Jun 24 12:42:01 serversuit CROND: (root) CMD (echo "hello" > /tmp/testfile)
Also you can send all output to some file:
/scripts/testscript.sh &> /logs/testscript.log
Take a look here for more examples of cron job troubleshooting.