Linux usage records --- automatic backup MySQL and web folders to windows shared path

Environment: CentOS 7 under with two PHP website and MySQL database, you need to backup site content and databases to windows on the shared storage

: Thinking in Centos Create a temporary folder, back up two databases to a temporary folder, and then back up Web file to a temporary folder, mount the windows under the shared folder, copy the files in the temporary folder to back up the path to the mount after the copy is completed unloading mount

 

Step Create a temporary backup path  

mkdir  /data/www/dbbak/


Step 2 Create a script   

    1 , backup MySQL database

cat  mysql_bak_mysqlname.sh
#!/bin/sh
# File: /data/www/dbbak/mysql_bak_mysqlname.sh
# Database info
/usr/bin/mysqldump   -u'mysqlusername' -p'mysqlpassword'  --databases  mysqlname |gzip > /data/www/dbbak/mysqlname_dump_`/bin/date +%Y%m%d_%H%M%S`.sql.gz


     2 , backup Web files

cat  bakweb.sh
#!bin/bash 
tar -zcvf /data/www/dbbak/www_dump_`/bin/date +%Y%m%d_%H%M%S`.tar.gz  /data/www/default/

  ------------------------      ----------------------------------------------------------------        --------------------------

   Target path after the backup file name path (to be backed up web file path)                                                                

   3, mount windows shared folders

cat  mount_ato.sh
#!bin/bash 
mount -t cifs -o username="share username",password="share passwd"  //192.168.1.***/ServerBackup/Liunxbackup/WEB   /data/www/dbbak/winbak/

                                 ----------------                     ------------          ----------------------------------------------               -------------------------

                                 Share Username shared user password           windows shared path to mount Linux path                                                                                    

 

   4 , the backup copy of the file to mount the windows of the path

cat copy_ato.sh
#!bin/bash 
\cp   /data/www/dbbak/**_dump_**.gz   /data/www/dbbak/winbak/

----     --------------------------------------------        ---------------------------------

 Directly covers to be copied when copying files to the loading path

 

    5、卸载挂载路径

cat umount_ato.sh
#!bin/bash 
umount /data/www/dbbak/winbak/

 

    6、创建自动执行脚本

cat  auto_bak.sh
#!bin/bash
/bin/sh /data/www/dbbak/mysql_bak_mysqlname.sh
/bin/sh /data/www/dbbak/mount_ato.sh
/bin/sh /data/www/dbbak/bakweb.sh
/bin/sh /data/www/dbbak/copy_ato.sh
/bin/sh /data/www/dbbak/umount_ato.sh

 

步骤3     创建定时备份任务

crontab -e
#每周五 23:00 执行备份MySQL和Web到windows共享路径下
00 23 * * 5  /bin/sh  /data/www/dbbak/auto_bak.sh


        


Guess you like

Origin blog.51cto.com/10006647/2431293