sh db / file备份脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh db / file备份脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash

sitedir="/srv/www"
filedir="/root/file_backups/today"
logs="/root/file_backups/logs"

tbackups="/root/file_backups/today"
ybackups="/root/file_backups/yesterday"

curday=$(date +"%_d")

echo "`date`" > $logs/backups.log

rm $ybackups/* >> $logs/backups.log
mv $tbackups/* $ybackups/ >> $logs/backups.log

cd "$sitedir"

for i in */; do
        tar -czf $tbackups/${i%%/}".tar.gz" ${i%%/}
        echo -e "\r\nBackup of ${i%%/} successfull" >> $logs/backups.log
done

cd "$filedir"

for i in */; do
        if [ $curday -eq 14 ]; then
        scp ${i%%/}".tar.gz" u106143@u106143.your-backup.de:/file_backups/14th
        elif [ $curday -eq 28 ]; then
        scp ${i%%/}".tar.gz" u106143@u106143.your-backup.de:/file_backups/28th
        fi
done

exit 0
#!/bin/bash

logs="/root/db_backups/logs"
bdir="/root/db_backups/today"

mysql_user="backup"
mysql_password="webiumbackup"

mysql=/usr/bin/mysql
mysqldump=/usr/bin/mysqldump

tbackups="/root/db_backups/today"
ybackups="/root/db_backups/yesterday"

curday=$(date +"%_d")

echo "`date`" > $logs/backups.log

rm $ybackups/* >> $logs/backups.log
mv $tbackups/* $ybackups/ >> $logs/backups.log

databases=`$mysql --user=$mysql_user -p$mysql_password -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`

for db in $databases; do
        $mysqldump --force --opt --user=$mysql_user -p$mysql_password $db | gzip > "$tbackups/$db.gz"
        echo -e "\r\nBackup of $db successfull" >> $logs/backups.log
done

cd $bdir

for i in */; do
        if [ $curday -eq 7 ]; then
        scp ${i%%/}".gz" u106143@u106143.your-backup.de:/db_backups/7th
        elif [ $curday -eq 14 ]; then
        scp ${i%%/}".gz" u106143@u106143.your-backup.de:/db_backups/14th
        elif [ $curday -eq 21 ]; then
        scp ${i%%/}".gz" u106143@u106143.your-backup.de:/db_backups/21th
        elif [ $curday -eq 28 ]; then
        scp ${i%%/}".gz" u106143@u106143.your-backup.de:/db_backups/28th
        fi
done

exit 0

以上是关于sh db / file备份脚本的主要内容,如果未能解决你的问题,请参考以下文章

sh 用于Postgresql DB自动备份的脚本

Oracle数据库RMAN的自动备份脚本简介

db2定时任务备份脚本

linux数据库和文件夹定时备份删除

mysql+ftp+shell脚本自动实现数据库的备份

Linux 下Mysql自动备份脚本