A scheduled backup script on MySQL line

Source: Internet
Author: User

MySQL database remote backup data preferably packed and compressed

[Email protected] crontab]# pwd
/data/mysql_bakup/crontab
[email protected] crontab]# cat backup_db_wangshibo.sh
#!/bin/bash
Mysql= "/usr/bin/mysql"
mysqldump= "/usr/bin/mysqldump"
Backup_dir= "/data/mysql_bakup"
#DB_SOCKET = "/var/lib/mysql/mysql.sock"
Db_hostname= "110.120.11.9"
Dbname= "Wangshibo"
Db_user= "Db_wangshibo"
Db_pass= "Mhxzk3rfzh"
Time= ' Date +%y%m%d%h%m%s '
Lock_file= "${backup_dir}/lock_file.tmp"
Bkup_log= "/data/mysql_backup/${time}_bkup.log"
del_bak= ' date-d ' days ago ' +%y%m%d '
# #To Judge Lock_file
if [[-F $LOCK _file]];then
Exit 255
Else
echo $$ > $LOCK _file
Fi

# #dump databases##
Echo ${time} >> ${bkup_log}
echo "=======start bakup============" >>${bkup_log}
#${mysqldump}-H ${db_hostname}-u${db_user}-p${db_pass}--databases ${dbname} | gzip-9 > ${backup_dir}/${time}.${dbname}.gz
${mysqldump}-H ${db_hostname}-u${db_user}-p${db_pass}--databases ${dbname} |gzip-9 > ${backup_dir}/${time}.${ Dbname}.gz
echo "=======finished bakup============" >>${bkup_log}
/bin/rm-f ${lock_file}

# #del back ten days before##
/bin/rm-f ${backup_dir}/${del_bak}*.gz

Scheduled backups
[Email protected] mysql_bakup]# crontab-l
Ten 0,6,12,18 * * */bin/bash/data/mysql_bakup/crontab/backup_db_wangshibo.sh >/dev/null 2>&1


[Email protected] crontab]# Cd/data/mysql_bakup
[[email protected] mysql_bakup]# ls
20161202061001.wangshibo.gz

A scheduled backup script on MySQL line

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.