备份显示错误的站点和数据库的脚本

时间:2014-07-11 20:44:08

标签: linux shell backup

我不是这方面的专家,但我想创建一个脚本,我可以将其变成一个cron作业,在我的家庭服务器上运行网站和数据库的备份。我找到了这个脚本并将其自定义为我的设置:

#!/bin/sh

THESITE="ic.sitescribersdev.com"
THEDB="zadmin_ironcowboy"
THEDBUSER="xxxxxx"
THEDBPW="xxxxxx"
THEDATE=`date +%d%m%y%H%M`

mysqldump -u $THEDBUSER -p${THEDBPW} $THEDB | gzip >        /var/zpanel/hostdata/zadmin/public_html/$THESITE/backups/files/dbbackup_${THEDB}_${THEDATE}.bak.gz

tar czf  /var/zpanel/hostdata/zadmin/public_html/$THESITE/backups/files/sitebackup_${THESITE}_${THEDA    TE}.tar -C / var/zpanel/hostdata/zadmin/public_html/$THESITE
gzip  /var/zpanel/hostdata/zadmin/public_html/$THESITE/backups/files/sitebackup_${THESITE}_${THEDA TE}.tar

find /var/zpanel/hostdata/zadmin/public_html/$THESITE/backups/files/site* -mtime +5 -exec rm {} \;
find /var/zpanel/hostdata/zadmin/public_html/$THESITE/backups/files/db* -mtime +5 -exec rm {} \;

我试图在ssh中运行它以查看它是否会输出数据,但我收到此错误:

arudd@new-host-3:/var/zpanel/hostdata/zadmin/public_html/ic_sitescribersdev_com/backups$ sudo sh backup.sh
: not found2: backup.sh: 
: not found8: backup.sh: 
: Directory nonexistent_zadmin_ironcowboyar/zpanel/hostdata/zadmin/public_html/ic.sitescribersdev.com
'@'localhost' (using password: YES) when trying to connectwboy
: not found10: backup.sh: 
tar: var/zpanel/hostdata/zadmin/public_html/ic.sitescribersdev.com\r\r: Cannot stat: No such file or directory
tar (child): /var/zpanel/hostdata/zadmin/public_html/ic.sitescribersdev.com\r/backups/files/sitebackup_ic.sitescribersdev.com\r_1107141435\r.tar: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
: No such file or directoryc.sitescribersdev.com.sitescribersdev.com
: not found13: backup.sh: 
find: missing argument to `-exec'
find: `/var/zpanel/hostdata/zadmin/public_html/ic.sitescribersdev.com\r/backups/files/db*': No such file or directory

任何帮助我做错的工作都会让你感到非常棒。

谢谢!

1 个答案:

答案 0 :(得分:0)

我明白了。由于脚本是在windows中制作的,因此抛出错误。我所要做的就是在脚本上安装并运行dos2unix,然后就像魅力一样!