Difference between revisions of "Automating your backups with cron"

From docwiki
Jump to: navigation, search
Line 21: Line 21:
   
 
which opens up your default editor. You can set a different editor with
 
which opens up your default editor. You can set a different editor with
 
   
 
<pre>
 
<pre>
Line 27: Line 26:
 
</pre>
 
</pre>
   
  +
The system wide crontab can be found under '''/etc/crontab''' compared to the user contabs it has a slightly different format: After the block that specifies the time and before the command there is a field that contains the user that should be used to run this command. This field is not there in the user crontabs because each user can only run commands under their user-privileges there.
 
   
 
== Example Crontab ==
 
== Example Crontab ==

Revision as of 12:40, 29 October 2020

Motivation

If you only do your backup when you hear about a case of someone loosing data then you will not have a recent backup when you need it. So you should automate the backup process. If you want to run a certain command at a regular interval then you can use the unix cron tool.

User and System Crontab

cron has a text based configuration file that contains the commands that should be run and when they should be run. There is a system crontab for all users and each user has his/her own crontab:

You can view this with
crontab -l

And edit it with:

crontab -e

which opens up your default editor. You can set a different editor with

export EDITOR=/usr/bin/yourfavoriteeditor

The system wide crontab can be found under /etc/crontab compared to the user contabs it has a slightly different format: After the block that specifies the time and before the command there is a field that contains the user that should be used to run this command. This field is not there in the user crontabs because each user can only run commands under their user-privileges there.

Example Crontab