联系我们:416326801#qq.com(#改成@)

Latest from the blog

Linux服务器备份文件和数据库并上传到ftp

标签: 备份 MySQL Shell Linux

#!/bin/sh

backupdir="/home/data/backup/"
if [ ! -d $backupdir ];then
        mkdir $backupdir
fi

# mkdir today backup
today=`date +%Y-%m-%d_%H_%M_%S`
fpath=$backupdir$today 
echo $fpath
if [ ! -d $fpath ];then
        mkdir $fpath
fi

# delete old file 
find $backupdir -type f -mtime +7 -print -exec /bin/rm -f {} \;

FL=`cat /usr/local/backup/file_list`
for i in $FL ;do
        cp -Rp $i $fpath
done

#backup mail dir
find /home/data/domains -type d >$fpath/maildirlist

# backup mysql all
/usr/local/bin/mysqldump --all-databases -uroot -pyourpasswd >$fpath/mysql_all.sql

# backup my self 
cp -Rp $0 $fpath
cp -Rp /usr/local/backup/file_list $fpath

cd $backupdir
tar czf $today.tar.gz $today
rm -rf $today
cd -

# ftp ...
ftp -n<<!
open 192.168.1.3 21
user backup backup
binary
lcd $backupdir
prompt off
mdelete *
mput *
bye
!

MySQL数据库备份脚本

标签: 备份 MySQL Shell Linux

#!/bin/sh
cd /home/backups/sql/
mkdir /home/backups/extmail
 
# Remove old backups
find /home/backups/sql/* -mtime +5 -exec rm -fr {} \; > /dev/null 2>&1
 
# Create the filename for the backup
eval `date "+day=%d; month=%m; year=%Y; hour=%H; min=%M; sec=%S"`
INSTFIL="extmail-backup-$year$month$day-$hour$min$sec"
 
# Dump the MySQL Database
#touch /home/backups/extmail/$INSTFIL.txt
/usr/local/bin/mysqldump -usqlback -p"sqlbackup" --opt extmail > /home/backups/extmail/$INSTFIL.sql
 
# Gzip the whole folder
 
tar -Pcpzf /home/backups/sql/$INSTFIL.tar.gz /home/backups/extmail/*
 
# Remove the SQL Dump
rm -rf /home/backups/extmail

备份Mysql并上传到ftp服务器

标签: 备份 MySQL Shell Linux

#!/bin/bash

#MySQL设置
MysqlHost=localhost
MysqlUser=root
MysqlPwd=password

#备份文件设置
BackupPath=/backup/db
FileName=$MysqlHost-$(date +%Y%m%d-%H%M%S)
FileFullPath=$BackupPath/$FileName

#ftp设置
FtpHost=10.206.4.121
FtpUser=iptv
FtpPwd=StarIptv
FtpPath=/ftp/backup/mysql

mkdir -p $BackupPath

#备份mysql并导出到文件
mysqldump -u$MysqlUser -p$MysqlPwd -h$MysqlHost --opt --all-databases -f > $FileFullPath.sql

#压缩备份文件
tar -Pzcvf $FileFullPath.tar.gz $FileFullPath.sql

#上传到ftp
ftp -n $FtpHost <<AUTOEOF
quote USER $FtpUser
quote PASS $FtpPwd
cd $FtpPath
binary
put $FileFullPath.tar.gz $FtpPath/$FileName.tar.gz
quit
AUTOEOF

#删除SQL文件
rm -rf $FileFullPath.sql

#删除30天之前的文件
find $BackupPath -type f -mtime +30 -exec rm -f {} \;