Cron
cron and backups
current crontab in /var/spool/cron/crontab/pathbost <syntaxhighlight>
- m h dom mon dow command
- backup MYSQL databases every 4 days (starting at 3:00AM)
00 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php sitebuil_wikidb 05 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php sitebuil_wrdp1 10 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php sitebuil_wuffdb 15 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php taxplans 20 3 */4 * * cd /home/sitebuil/scripts/S3-Site-Backups; php s3cli_backupDb.php webeshoppin
- Delete all local backups older than 3 weeks (at 2am)
00 2 * * * find /var/backups/backup/*.gz -ctime +21 -type f -print | xargs rm -f </syntaxhighlight> crontab to delete files older than 21 days
#Delete all local backups older than 3 weeks (at 2am) 00 2 * * * find /PATH/TO/HOME_DIR/backups/*.gz -ctime +21 -type f -print | xargs rm -f #Run it every three days... 0 0 */3 * *
- cron tutorial another
- Re: Where is crontab stored?
- Root-level crontab should be in /etc/crontab.
- Root-level anacron and periodics should be in /etc/cron*
- User-level crontabs should be in /var/spool/cron/crontabs - they are listed by user, pathbost isactually a chrontab
- select-editor
installing and testing a crontab
installing
- even after you change it by yourself you can install it by running as root
sudo crontab -u pathbost /var/spool/cron/crontabs/pathbost
testing
* * * * * /bin/echo " pathGZoobar $(date) " >> /usr/local/docs/testcron.txt
will append this every minute to testcron.txt
pathGZoobar Thu Jan 3 14:15:01 EST 2013
You can check the logs to see if the crontab got installed/executed by running as root
sudo tail /var/log/syslog
vi with crontab 101
- su to user then 'crontab -e'
- 'i' to insert text
- 'esc :wq to save change, and quit
- then crontab is installed
- 'esc :q!' exits without saving (or installing)
- you can kill your crontab with crontab -r
- you can list the installed crontab with crontab -l
backup to s3
Backups have a 30 day life on s3 and a 21 day life in /var/backups/backup backup_to_S3 code
directory backup
To backup a directory run this from the terminal:
sudo php /home/sitebuil/scripts/S3-Site-Backups/s3cli_backupDir.php /home/sitebuil/public_html/doku doku
database backup
sudo php php /home/sitebuil/scripts/S3-Site-Backups/s3cli_backupDb.php sitebuil_wiki
or goto http://pathboston.com/zstill/stillwater.html
refs
- http://www.cenolan.com/2008/05/simple-linux-to-amazon-s3-backup-script/
- http://www.alvechurchdata.co.uk/softhanoi.htm
- http://s3tools.org/s3cmd
- http://tagmycode.com/snippet/480/backup-mysql-database-to-amazon-s3-with-s3cmd-on-debian#.UMifCoP2GSo
- http://docs.amazonwebservices.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html
- http://en.wikipedia.org/wiki/Backup_rotation_scheme
- http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/
string meaning ------ ------- @reboot Run once, at startup @yearly Run once a year, "0 0 1 1 *" @annually (same as @yearly) @monthly Run once a month, "0 0 1 * *" @weekly Run once a week, "0 0 * * 0" @daily Run once a day, "0 0 * * *" @midnight (same as @daily) @hourly Run once an hour, "0 * * * *"