BDMV.INFO

Title: [2014.02.16] Add the Backup Script into Crontab Job [Print this page]

author: 夢    time: 2014-2-16 13:17     Title: [2014.02.16] Add the Backup Script into Crontab Job

I would like to add a shell script to crontab, I hope to relay on the script and  the cloud sync app to save the backup of something imoportant files liking database or file system every day.



<Some key points people need to pay attention>
1. Permission : if the script user of the crontab (/etc/crontab) is root, the script need change the ower to root and provide the writing permission to root.
2. Abolute patch : Because of the script has a lot of commands  doing rar ot gizp archive, the location of compressing target use the absulute patch is better. ( See below example picture)
3. Put the #!/bin/sh at the script begaining : In ubuntu sh is the same as the command dash and in the centos is the same as bash, in fact, I still can't know all the difference of dash and bash. (See below example picture)
4. Crontab limition: people need serach much more detail information form google/wikipedia yourself, some script grammar may different with crontab.



[hide=7777]
#!/bin/sh
/etc/init.d/lighttpd stop
nice -n 19 mysqldump -u goddesschi -peb4006 DISCUZX2 | nice -n 19 gzip -9 > /home/goddesschi/sync/copy/$(date '+%Y-%m%d-%H%M').DB-DISCUZX2.sql.gz
nice -n 19 mysqldump -u alanchuangi -p#2Riiiaiimw --default-character-set=binary MEDIAWIKI | nice -n 19 gzip -9 > /home/goddesschi/sync/copy/$(date '+%Y-%m%d-%H%M').DB-MEDIAWIKI.sql.gz
nice -n 19 rar a -m0 -hphttp://bdmv.info/snow -rr5 -ep1 /home/goddesschi/sync/copy/$(date '+%Y-%m%d-%H%M').www.rar /var/www/index.html.backup /var/www/phpinfo.php /var/www/php-script /var/www/pma /var/www/snow /var/www/snowiki /var/www/snowpress /var/www/tc
nice -n 19 rar a -m0 -hphttp://bdmv.info/snow -rr5 -ep1 /home/goddesschi/sync/copy/$(date '+%Y-%m%d-%H%M').mysql.rar /var/lib/mysql
nice -n 19 rar a -m0 -hphttp://bdmv.info/snow -rr5 -ep1 /home/goddesschi/sync/copy/$(date '+%Y-%m%d-%H%M').other.rar /etc/rc.local /etc/lighttpd/lighttpd.conf /etc/crontab ~/.bash_history /usr/local/etc/proftpd.conf /home/goddesschi/rt/ls
/etc/init.d/lighttpd start

[/hide]

---------------reference---------------
http://www.pcdvd.com.tw/showthread.php?t=1039626
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?topic_id=79374
http://tigermax.dyndns.org/bbs/forum.php?mod=viewthread&tid=9449
http://2d-gate.org/thread-5128-1-1.html
http://stackoverflow.com/questions/8967902/why-do-you-need-to-put-bin-bash-at-the-beginning-of-a-script-file
http://www.mkssoftware.com/docs/man1/crontab.1.asp
http://linux.vbird.org/linux_basic/0340bashshell-scripts.php








Welcome to BDMV.INFO (http://bdmv.info/snow/) Powered by Discuz! X2