Using cron to perform automatic back-ups
cron is a mechanism to automatically run commands or scripts. Users can set-up scripts that run within their home folder. Root cron jobs can perform system-wide tasks, such as backing up all users home directory. Usually you want to back-up servers as root, so that all user's files are backed up.
The file that regulates cron jobs has a specific format that is managed using a text editor called crontab.
- SSH into your Pi as root.
- crontab -e invokes the nano text editor and opens the /etc/crontab file.
- Set the time and date you want the cron job to run and enter the command or script you wish to run.
- When you save and exit, Linux automatically writes the needed system files.
- If you need to delete a cron job, use crontab -e again. Do not attempt to edit system cron files manually.
Crontab and cron files must follow a certain format. Direct manual editing of these files does not work. There are many examples of udsing crontab on the internet to follow.
crontab explained