2013年3月1日 星期五

[Crontab] Backup the folder everyday by using crontab

1. The scrtip like below
############### Crontab Script  #####################
#!/bin/bash
# cp file from A place to tftp
DATE=`date +%Y%m%d-%H-%M`
NowFolder='/home/cvsroot/'
TarFile='happy-'$DATE'.tar.gz'

bash -c "find $BackupFolder -mtime +5 -type f | xargs rm -rf"

cd $NowFolder

#tar czvf $TarFile happy/ >> ./logfile.txt
bash -c "tar czvf $TarFile happy/ >> ./logfile.txt"
bash -c "scp $NowFolder'/'$TarFile root@111.2.1.93:/home/rober/CVScode/"

#################################################


Red one is most important one. If no add bash -c, this script will not work properly.

       -c string If  the  -c  option  is  present, then commands are read from
                 string.  If there are arguments after the  string,  they  are
                 assigned to the positional parameters, starting with $0.


Reference :

0 意見:

張貼留言