42

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.

3
  • 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. Commented Nov 18, 2011 at 8:46
  • related: "What I can I do to make the transition to some new computer hardware safe and smooth?". Commented Nov 18, 2011 at 13:19
  • With regard to your username, sorry to take away your '666' upvote count -but I found the post useful. ;) Commented Sep 19, 2013 at 15:30

4 Answers 4

59

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

0
30

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

12

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

2
  • 2
    For Ubuntu 14.04 at least, the relevant files are in the directory /var/spool/cron/crontabs. Commented Jan 22, 2015 at 1:31
  • @KennyEvitt and you must be the root to access it sudo -i Commented Apr 23, 2016 at 9:43
5

I made my backup into a cron job.

0 9 * * * crontab -l | gzip > /backups/'crontab-'$(date +"\%Y\%m\%d-\%H\%M\%S")'.gz' 
1
  • Seriously, you gzip it? Is that even reducing the file size? Commented Oct 31, 2023 at 14:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.