Shell simple full-backup mysql script case _ MySQL

Source: Internet
Author: User
Shell simple full-backup mysql script case bitsCN.com
Shell simple full-backup mysql script case [root @ cacti mysql] # cat backup. sh #! /Bin/sh # 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 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] # restore 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[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. mysql> use backupDatabase changedmysql> show tables; + ------------------ + | Tables_in_backup | + ------------------ + | B | t | + ---------------- + 2 rows in set (0.00 sec) mysql> exitBye
BitsCN.com

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.