Absolutely maddening. x(
Trying to write my first script.
Can anyone tell me why I keep ending up with empty gzipped files?
Trying to write my first script.
Can anyone tell me why I keep ending up with empty gzipped files?
Code:
[root@zap]/root/bin-> cat db.backup
#!/usr/local/bin/bash
user=XXXXXXXX #Mysql Username
pass=XXXXXXXX #Mysql Password
bd=/root/test #Backup Directroy
# Database Names to back up
declare -a dbs=(mysql connect_db)
date=`date +%m-%d-%y`
time=`date '+TIME: %H:%M:%S'`
ld=$bd/log
ed=$bd/error
lf=$ld/backup.log_$date
ef=$ed/error.log_$date
num=${#dbs[@]}
######################## Begin Script #########################
# Create Backup Dir and chmod if not there
if [ ! -d $bd ]; then
mkdir $bd $ld $ed
chmod -R 700 $bd
echo "--- File created $date $time ---" >>$lf
echo "--- File created $date $time ---" >>$ef
fi
# Write Header to the logfile
echo "===================================================" >>$lf
echo "MYSQL DATABASE BACKUP STARTED AT $date $time" >>$lf
echo "Number of Databases = $num"
for ((i=0 ; i < $num ; i++)); do
mysqldump -u$user -p$pass --default-character-set=utf8 ${dbs[$i]} > $bd/${dbs[$i]}_RAW
gzip -q $bd/${dbs[$i]}_RAW > $bd/${dbs[$i]}_$date.gz && rm $bd/${dbs[$i]}_RAW
done
exit
# Write Footer to dump cycle
echo "MYSQL DATABASE BACKUP COMPLETED AT $date $time" >>$lf
exit
[root@zap]/root/bin->
Code:
[root@zap]/root/bin-> ./db.backup
Number of Databases = 2
mysqldump: Got error: 1033: Table './mysql/general_log' was created with a different version of MySQL and cannot be read when using LOCK TABLES
rm: /root/test/mysql_RAW: No such file or directory
rm: /root/test/connect_db_RAW: No such file or directory
[root@zap]/root/bin->
Code:
[root@zap]/root/bin-> ls -la /root/test
total 172
drwx------ 4 root wheel 512 Jul 18 08:16 .
drwxr-xr-x 4 root wheel 512 Jul 18 08:15 ..
-rw-r--r-- 1 root wheel 0 Jul 18 08:16 connect_db_07-18-12.gz
-rw-r--r-- 1 root wheel 153282 Jul 18 08:16 connect_db_RAW.gz
drwx------ 2 root wheel 512 Jul 18 08:15 error
drwx------ 2 root wheel 512 Jul 18 08:15 log
-rw-r--r-- 1 root wheel 0 Jul 18 08:16 mysql_07-18-12.gz
-rw-r--r-- 1 root wheel 303 Jul 18 08:16 mysql_RAW.gz
[root@zap]/root/bin->