Welcome to the Linux community forum and interact with the 2 million technical staff to edit the script file [python] viewplaincopyprint? Db_userrootdb_passwd123456db_hostlocalhostbackup_dirusrlocalapache2htdocsbackuptime $ (date + % Y % m % d % H % M) MYSQLu
Welcome to the Linux community forum and interact with 2 million technicians> edit the script file [python] view plaincopyprint? Db_user = "root" db_passwd = "123456" db_host = "localhost" backup_dir = "/usr/local/apache2/htdocs/backup" time = "$ (date +" % Y % m % d % H % M ") "MYSQL ="/u
Welcome to the Linux community forum and interact with 2 million technicians>
Edit script file
[Python] view plaincopyprint?
Db_user = "root" db_passwd = "123456" db_host = "localhost" backup_dir = "/usr/local/apache2/htdocs/backup" time = "$ (date +" % Y % m % d % H % M ") "MYSQL ="/usr/local/mysql/bin/mysql "MYSQLDUMP ="/usr/local/mysql/bin/mysqldump "MKDIR ="/bin/mkdir "RM =" /bin/rm "MV ="/bin/mv "GZIP ="/bin/gzip "test! -W $ backup_dir & echo "Error: $ backup_dir is un-writeable." & exit 0 test! -D "$ backup_dir/$ time" & $ MKDIR-p "$ backup_dir/$ time" all_db = "$ ($ MYSQL-u $ db_user-h $ db_host-p $ db_passwd-Bse 'show databases ')"
For db in $ all_db do $ MYSQLDUMP "-default-character-set = gbk"-u $ db_user-h $ db_host-p $ db_passwd $ db | $ GZIP-9>" $ backup_dir/$ time/mongodb.gz "done exit 0;
Set scheduled task
Use the crontab-e command to edit the scheduled task list
[Html] view plaincopyprint?
15 3 *** sh/usr/scripts/mysql_backup.sh
Indicates that the script is executed at 03:15 every day for database backup.