33

I want to do a complete server backup.

I already have my backup script copying all of the html/php files for the web app, and the mysql databases, placing them into a .tar.gz file.

How can I add the crontab files to that backup?

Whenever I save the crontab, it goes to /tmp folder.. and when I check that folder immediately afterwards, it is empty.

darkAsPitch
  • 1,861
  • 4
  • 25
  • 42
  • Just a though, may versions of cron allow root to place the jobs in `/etc/cron.d/`, I generally prefer that instead, since my /etc folder is backed up, and tracked in a VCS. – Zoredache Nov 18 '11 at 08:46
  • related: ["What I can I do to make the transition to some new computer hardware safe and smooth?"](http://unix.stackexchange.com/questions/8272/what-i-can-i-do-to-make-the-transition-to-some-new-computer-hardware-safe-and-sm). – David Cary Nov 18 '11 at 13:19
  • With regard to your username, sorry to take away your '666' upvote count -but I found the post useful. ;) – a coder Sep 19 '13 at 15:30

4 Answers4

50

You could just backup the entire /var/spool/cron directory. It contains all crontabs for all users.

dtoubelis
  • 4,579
  • 1
  • 28
  • 31
24

You can periodically run crontab -l > my_crontab.backup to backup the crontab into file.

mitbal
  • 341
  • 2
  • 4
11

just backup the file /var/spool/cron/USER_NAME

Bart De Vos
  • 17,761
  • 6
  • 62
  • 81
chocripple
  • 2,039
  • 14
  • 9
4

I made my backup into a cron job.

0 9 * * * crontab -l | gzip > /backups/'crontab-'$(date +"\%Y\%m\%d-\%H\%M\%S")'.gz'