#========================start shell Script ============================#!/bin/bash# defines the user name and password to use when backing up the database db_user= "root" db _passwd= "111111" #定义FTP服务器地址, user name, password, directory Ftp_url=113.108.8.80ftp_user=ftpuserftp_passwd=111111ftp_dir=/mysql_ backup/xxxx# database backup path backup_dir=/home/mysqlbak# current date time= ' Date +%y%m%d ' #得到所有数据库名的sqlsql = "Show Databases" # Get all database names declare databases= ' Mysql-u${db_user}-p${db_passwd}-E "${sql}" ' #循环数据库名列表, perform backup for db_name in $databasesdoif [$ Db_name! = "Database"] && [$db _name! = "Information_schema"] && [$db _name! = "MySQL"] && [$d B_name! = "Test"]; Thenecho "The item is $db _name"/usr/bin/mysqldump-u$db_user-p$db_passwd-r-e-b $db _name > "$backup _dir/$db _name "_" $time. sql "fidone# Delete backup directory files older than seven days ago find $backup _dir-name ' *.sql '-type f-mtime +7-exec rm {} \; #压缩文件cd $backup _dir Zip-m db_$time.zip *_$time.sql# Upload file ftp-d-n <<!open "$ftp _url" user "$ftp _user" "$ftp _passwd" passive BINARYCD $ft P_DIRLCD $backup _dirpromptput Db_$time.zipclosebye!#====================end Shell Script ======================
passive: Switch passive mode, where the upload needs to use active mode, plus the control switch passive mode to see the situation plus if the upload using passive mode Entering Passive Mode error
Binary: Binary transfer
CD: Server side CD LCD: Client CD put upload single mput upload multiple get download single mget download multiple Prompt Multiple Tips
#========================start Shell Script ============================#!/bin/bash
#定义备份数据库时使用的用户名和密码db_user = "root" db_passwd= "111111"
#定义FTP服务器地址, user name, password, directory ftp_url=113.108.8.80ftp_user=ftpuserftp_passwd=111111ftp_dir=/mysql_backup/113.108.8.82
#数据库备份的路径backup_dir =/home/mysqlbak
#当前日期time = ' Date +%y%m%d '
#得到所有数据库名的sqlsql = "Show Databases"
#得到所有数据库名declare databases= ' Mysql-u${db_user}-p${db_passwd}-E "${sql}" '
#循环数据库名列表, perform a backup for db_name in $databasesdoif [$db _name! = "Database"] && [$db _name! = "Information_schema"] &am p;& [$db _name! = "MySQL"] && [$db _name! = "Test"]; Thenecho "The item is $db _name"/usr/bin/mysqldump-u$db_user-p$db_passwd-r-e-b $db _name > "$backup _dir/$db _name "_" $time. sql "Fidone
#删除备份目录下早于七天前的文件find $backup _dir-name ' *.sql '-type f-mtime +7-exec rm {} \;
#压缩文件cd $backup _dirzip-m db_$time.zip *_$time.sql
#上传文件ftp-D-N <<!open "$ftp _url" user "$ftp _user" "$ftp _passwd" passive BINARYCD $ftp _DIRLCD $backup _dirpromptput D b_$time.zipclosebye!
#====================end Shell Script ======================
Linux backup database and upload to remote server (scheduled execution shell for FTP upload)