腐败的mysqldump tarball

时间:2013-09-19 10:58:28

标签: zip mysql-backup

我正在使用以下脚本来创建mysql备份并压缩它。但结果.GZ文件总是损坏。当我尝试提取时,我得到了这个。

root@nix [/mysql_dumps/backup.16021]# tar -zxvf mysql-icme2193_icmedb-201309191523.gz
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

文件损坏可能是什么原因?从5小时开始撞到我的头上。

这是代码。

    #!/bin/sh
# System + MySQL backup script
# Full backup 
# This script is licensed under GNU GPL version 2.0 or above
# Modified from http://bash.cyberciti.biz/backup/wizard-ftp-script.php
# ---------------------------------------------------------------------
### System Setup ###
DIRS=""
BACKUP=/mysql_dumps/backup.$$
NOW=$(date +"%Y%m%d%H%M")
DAY=$(date +"%a")
### MySQL Setup ###
MUSER="root"
MPASS="****"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
### FTP server Setup ###
FTPD="/mysql_dumps/direname"
FTPU="backupf"
FTPP="****"
FTPS="46.xxx.xxx.xxx"
FTP="$(which ftp)"
### Other stuff ###
EMAILID="notify@example.com"


### do not edit below this line unless you know what you are doing ###
### Start Backup for mysql system ###
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
# Get databases name
DBS="database_name"
FILE=$BACKUP/mysql-$DBS-$NOW.gz
$MYSQLDUMP --no-tablespaces --skip-lock-tables --add-drop-table -u $MUSER -h $MHOST -p$MPASS $DBS | $GZIP -9 > $FILE

### Dump backup using FTP ###
#Start FTP backup using ftp
$FTP -inv $FTPS << END_SCRIPT
user $FTPU $FTPP
cd $FTPD
mkdir $FTPD
mkdir $FTPD/$NOW
cd $FTPD/$NOW
lcd $BACKUP
mput *
quit
END_SCRIPT

## remove temporary backups from local server
 rm -fR $BACKUP/
### Find out if ftp backup failed or not ###
if [ "$?" == "0" ]; then 
 T=/tmp/backup.pass
 echo "Date: $(date)">$T
 echo "Hostname: $(hostname)" >>$T
 echo "mySQL database backup done. Transferred backup to remote FTP site: $FTPS" >>$T
 mail  -s "[mysql $(hostname)] BACKUP Succeeded" "$EMAILID" <$T
 rm -f $T 
else
 T=/tmp/backup.fail
 echo "Date: $(date)">$T
 echo "Hostname: $(hostname)" >>$T
 echo "Backup failed" >>$T
 mail  -s "BACKUP FAILED" "$EMAILID" <$T
 rm -f $T
fi

2 个答案:

答案 0 :(得分:0)

你的脚本显然只是gzips文件,它不会先将它存档到tarball中。您需要创建一个tarball,或者只需使用gzip来“解压缩”该文件。

tar视为ziprar,它只是将您传递的所有数据放入单个存档文件中,就像文件夹一样。 gzip压缩它使它变小。

N.B:在收到的文件上你应该这样做:

root@nix [/mysql_dumps/backup.16021]# gzip -d mysql-icme2193_icmedb-201309191523.gz

答案 1 :(得分:0)

你的文件只有扩展名.gz,所以tar没有必要提取它。 只能使用:

 gzip -d yourfile.gz

使用tar你的文件将有tar.gz扩展名或tgz扩展名

查看以下链接:

http://www.cyberciti.biz/faq/howto-compress-expand-gz-files/