Shell simple full-Backup mysql script case

Source: Internet
Author: User


Shell simple full-backup mysql script case [root @ cacti mysql] # cat backup. sh #! /Bin/sh www.2cto.com # created by taiyang #2012-9-16 # function: backup mysql database # set local variablesDBname = backupBackupPath =/mysqlbak/DumpFile =$ {BackupPath }$ {DBname} 'date + % y % m % d _ % H % M % s '. bak v_username = 'root' if [$ v_username! = 'Root']; thenecho "ERROR: the script must be run as mysql" exit 1fi www.2cto.com echo "backup database path: $ DumpFile "echo" ---------------------------- "dateecho" *************************** "echo" backup database begin "echo" *************************** "mysqldump-uroot-proot -- opt $ DBname> $ DumpFile echo "***************************" echo" backup database end "echo" ************************** "date # delete backups before 5 daysfind $ BackupPath-ctime + 5-name '*. bak '-exec rm {}\; [root @ cacti mysql] # www.2cto.com restores the database information from the backup script;
[Root @ cacti mysqlbak] # lsbackup120928_114307.bak backup120928_114556.bak cacti120928_105558.bakbackup120928_114309.bak cacti120928_110443.bakbackup120928_114310.bak cacti120928_110443.bakbackup120928_114310.bak cacti120928_105155.bak cacti120928_110448.bakbackup120928_114311.bak cacti120928_110449.bak cacti120928_110449.bak [root @ cacti mysqlbak] # pwd/mysqlbak [root @ cacti mysqlbak] # [root @ cacti ~] # Mysql-hlocalhost-uroot-proot backup </mysqlbak/backup120928_114556.bak
[Root @ cacti ~] # Mysql-uroot-prootWelcome to the MySQL monitor. commands end with; or \ g. your MySQL connection id is 860 Server version: 5.0.22-log Type 'help; 'or' \ H' for help. type '\ C' to clear the buffer. www.2cto.com mysql> use backupDatabase changedmysql> show tables; + ------------------ + | Tables_in_backup | + tables + | B | t | + ---------------- + 2 rows in set (0.00 sec) mysql> exitBye
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.