開放samba分享目錄存放含中文檔名的資料,如果要定期壓縮備份,使用tar或rar都遇到中文檔名變成亂碼的問題。最後找到用7za可以解決這個中文亂碼的問題。
以下是以7za壓縮要備份的目錄並上傳至ftp
建立shell script "backup.sh"
#!/bin/bash
#START
TIME=`date +"%b-%d-%y"`
FILENAME="backup-$TIME.7z"
SRCDIR="/opt/accnt"
DESDIR="/tmp"
echo "Processing backup folder"
7za a -mx=9 $DESDIR/$FILENAME $SRCDIR
cd /tmp
echo "connect to ftp site"
USERNAME="username"
PASSWORD="password"
SERVER="ftp_ip"
# local directory to pickup *.7z file
#FILE="/tmp"
# remote server directory to upload backup
BACKUPDIR="home"
# login to remote server
ftp -n -i $SERVER <
user $USERNAME $PASSWORD
cd $BACKUPDIR
bin
mput $FILENAME
quit
EOF
rm --force $FILENAME
將backup.sh加入執行權限
chmod +x backup.sh
建立排程工作
ex:每週一、六 pm1:00執行/path/to/backup.sh
crontab -e
# Minutes Hours Day of Month Month Day of Week Command
01 13 * * 1,6 /path/to/backup.sh
Reference:
http://www.cyberciti.biz/faq/linux-unix-autologin-cron-ftp-script/
http://www.broexperts.com/2012/06/how-to-backup-files-and-directories-in-linux-using-tar-cron-jobs/
http://cybercentos.blogspot.tw/2013/11/install-7zip-on-centos-64-i686.html
crontab -e
# Minutes Hours Day of Month Month Day of Week Command 01 13 * * 1,6 /bin/bash /backup.sh- See more at: http://www.broexperts.com/2012/06/how-to-backup-files-and-directories-in-linux-using-tar-cron-jobs/#sthash.xZv1V1BL.dpuf
crontab -e
# Minutes Hours Day of Month Month Day of Week Command 01 13 * * 1,6 /bin/bash /backup.sh- See more at: http://www.broexperts.com/2012/06/how-to-backup-files-and-directories-in-linux-using-tar-cron-jobs/#sthash.xZv1V1BL.dpuf