Backup of crontab itself

Hi all

What is the best way of making backups (daily or week basis) of a crontab file? Scenario: one userid, acessed by a number of analysts, that has a crontab file contantly updated. It's a large file, with hundreds of entries.

Sometimes somebody deletes an entry that shoudn't be deleted.

HP-UX 11.23

Thanks

Run a cronjob to run "crontab -l > some_unique_file".

Who's "somebody"? You need better accountability, or some better communication, perhaps! How much depends on who's crontab file that is.

That's a good thought, backing up cron tables. You can dump out people's cron files with -l, so I might try this:

$ cat cron-back.sh

#!/bin/sh

trap "[ -d /tmp/$$ ] && rm -Rf /tmp/$$" EXIT

mkdir /tmp/$$ || exit 1

IFS=","
# Loop through all users in the cron group
for U in `awk -F":" '$1=="cron" { print $NF ; exit }' /etc/group`
do
        crontab -u "$U" -l > "/tmp/$$/$U"
done

tar -zcf cron-backup-`date +%Y-%m-%d`.tar.gz -C /tmp/$$ .

$ ./cron-back.sh
$ tar -ztf cron-backup-2012-10-04.tar.gz
./
./user1
./user2

$
1 Like