Use Copy to back up your Web site data to a network disk

Source: Internet
Author: User
Tags bz2 flush mkdir rar mysql backup

Use Copy to back up your Web site data

Download and run copy

The copy Linux version is a compiled, ready to run program that requires no additional installation

wget https://copy.com/install/linux/Copy.tgz
Tar zxvf copy.tgz
./copy/x86/copyconsole-username= registered copy of the mailbox-root= backup directory

In order for copy to be able to run itself (without taking up our terminal window), you can use the screen command to open screens for him to run (tutorials).

Divergent thinking

Through the above orders, we can easily complete the backup of the site file data, but the database has not yet been backed up, we can write a separate script, and crontab (tutorial) regularly back up the SQL and move it to the backup directory (note: Do not move SQL to the browser accessible directory, such as public _html Directory! )

At present, this method of magic has just come out, resource possession and other aspects have yet to be tested, but also welcome brainstorming, to give more and better solutions to the devil

Additional options

A backup script was sent to the mailbox with SendMail:

XML code
1.
2.#!/bin/bash
3.# X, SendMail hoodbc20117
4.### Setting Path ###
5.backpath= "/data0/mysql_bak" 6.date= '/bin/date ' +%y-%m-%d-%h-%m-%s ' 7.
8.ZIP-RQ $BACKPATH/erp_$date.zip/data/htdocs/www/erp/
9.echo "ERP All Backup" | Mutt-a $BACKPATH/erp_$date.zip-s "ERP all backup" bluehood24@163.com
10.
11.find $BACKPATH-ctime +30-name *.zip-delete

By the way, log the database backup script as well:


XML code
1.#!/bin/bash
2.# hoodbc20117
3.
4.### Database Setting ###
5.user= ' root ' 6.password= ' 7.host= ' 127.0.0.1 ' 8.databases= (ERP) 9.
10.### Setting Path ###
11.mysqldump=/usr/local/webserver/mysql/bin/mysqldump 12.backpath= "/data0/mysql_bak" 13.
14.date= '/bin/date ' +%y-%m-%d-%h-%m-%s ' 15.for DATABASE in ${databases[*]}
16.do
Filename= "$DATABASE-$DATE" 18.
$MYSQLDUMP--add-drop-table--user $USER--password= $PASSWORD $DATABASE--lock-all-tables>> "$BACKPATH/$FILE Name.sql "20.done
21st.
#tar zcf-r $BACKPATH/erp_$date.tar.gz ~/data/htdocs/www/erp
#zip-RQ $BACKPATH/erp_$date.zip/data/htdocs/www/erp/
24.ZIP-RQ $BACKPATH/$FILENAME. zip $BACKPATH/$FILENAME. sql
25.echo "ERP db Backup" | Mutt-a $BACKPATH/$FILENAME. zip-s "ERP db Backup" bluehood24@163.com
26.
27.find $BACKPATH-ctime +30-name *.sql-delete
Remember to add--lock-all-tables parameters so that when you export the SQL file will lock the table, of course, you can directly package the database files. Finally add to Crontab to run the script regularly.

1. Install Mutt mail Client
# yum Install Mutt-y
2. Create a script
# vi/etc/rc.d/mail_to_bak_daily.sh
(Version i)
------------------------------------------------------------
#!/bin/bash
# =========================================================
# Please enter which separate directory you want to put the backup data in
Basedir=/backup/daily
# =========================================================
Path=/bin:/usr/bin:/sbin:/usr/sbin::/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin;
Export PATH
Export Lang=c
# define Database Information
User=root
passwd=123456
# define MySQL backup path
mysql_db_bak= $basedir/mysql_db_bak/$ (date +%f_%h%m)
[!-D "$mysql _db_bak"] && mkdir-p $mysql _db_bak
# define WWW backup path
www_src_bak= $basedir/www_src_bak/$ (date +%f_%h%m)
[!-D "$www _src_bak"] && mkdir-p $www _src_bak
# define message attachment path
Mail_attach_mysql= $mysql _db_bak/wordpress.sql
mail_attach_www= $www _src_bak/www.tar.bz2
# define message Headers
mail_subject= "Www.example.com_daily_backup"
# Note: The characters between the headings here can not have spaces, if there are spaces will be issued according to the name of the message, such as daily@www.example.com,backup@www.example.com This example of the following underlined instead
# define message Content
Mail_content=/tmp/mail_content.txt
Mail_code= "Send Mysql_bak and WWW_SRC to/at $ (date +%f_%h%m)"
# define email Addresses
Mail_address= "Test@example.com"
# 1. Backup MySQL (database directory in/usr/local/mysql)
Mysqldump-u $user-p$passwd--opt--skip-lock-tables--flush-logs--database wordpress > $mysql _db_bak/wordpress.sql
# 2. Back up www source code:
Cd/usr/local
tar-jpcf $www _src_bak/www.tar.bz2 www
# 3. Message body
Cd/tmp
echo $mail _code > $mail _content
# 4. Send Attachments
Yum Install Mutt-y
Cat $mail _content |mutt-s $mail _subject-a $mail _attach_mysql-a $mail _attach_www--$mail _address
# 5. Clear Temporary files
Cd/tmp
RM-RF $mail _content
---------------------------------------------------------
(Version II) recommended
Note: This version will send the attachment separately, to send several large attachments to the mailbox at the same time the probability of not receiving, you can reconfigure the following version
--------------------------------------------------------
#!/bin/bash
Path=/bin:/usr/bin:/sbin:/usr/sbin::/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin;
Export PATH
Export Lang=c
# System File Backup path
Basedir=/backup/daily
# Database Information
User=root
passwd=123456
# define MySQL backup path
mysql_db_bak= $basedir/mysql_db_bak/$ (date +%f_%h%m)
if [!-d "$mysql _db_bak"];
Then
Mkdir-p $mysql _db_bak
Fi
# define WWW backup path
www_src_bak= $basedir/www_src_bak/$ (date +%f_%h%m)
if [!-d "$www _src_bak"];
Then
Mkdir-p $www _src_bak
Fi
# Backup files
mysql_bak= $mysql _db_bak/wordpress.sql.gz
www_bak= $www _src_bak/www.tar.bz2
# defines an array of backup files as attachments
all_bak= ($mysql _bak $www _bak)
# message Headers
mail_subject= "Www.showerlee.com_daily_backup"
# message Content
Mail_content_mysql= "Send Mysql_bak at $ (date +%f_%h%m)"
mail_content_www= "Send www_src at $ (date +%f_%h%m)"
# define an array of content
Mail_content= ("$mail _content_mysql" "$mail _content_www")
# Mail Address
Mail_address= "Test@example.com"
# 1. Backup MySQL (database directory in/usr/local/mysql)
Mysqldump-u $user-p$passwd--opt--skip-lock-tables--flush-logs--database WordPress | gzip > $mysql _bak
# 2. Back up www source code:
Cd/usr/local
tar-jpcf $www _bak www
# 3. Send Attachments
Yum Install Mutt-y
for ((i=0; i!=${#all_bak [@]}; ++i))
{
echo ${mail_content[i]} | Mutt-s $mail _subject $mail _address-a ${all_bak[i]}
}
# 4. Clean up mutt temporary files
Cat/dev/null > ~/sent
--------------------------------------------------------
(Version III)
Implement RAR split and send attachments
Recommended for users with attachments exceeding 50M
--------------------------------------------------------
#/bin/bash
Path=/bin:/usr/bin:/sbin:/usr/sbin::/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin;
Export PATH
Export Lang=c
# System File Backup path
Basedir=/data/backup/daily
# Database Information
User=root
passwd=123456
# Install RAR
rar=$ (rar | grep rar | awk ' {print $} ' | sed-n ' 1p ')
If [$?!= 0];then
Rar=null
Fi
sys_version=$ (UNAME-M)
Rar_path= "/usr/local/rar"
If [$rar!= ' rar '];then
if [$sys _version = ' x86_64 '];then
wget http://www.rarlab.com/rar/rarlinux-x64-4.2.0.tar.gz
Tar zxvf rarlinux-x64-4.2.0.tar.gz
MV RAR $rar _path
CD $rar _path
Make
Else
wget http://www.rarlab.com/rar/rarlinux-4.2.0.tar.gz
Tar zxvf rarlinux-4.2.0.tar.gz
MV RAR $rar _path
CD $rar _path
Make
Fi
Fi
# define MySQL backup path
mysql_db_bak= $basedir/mysql_db_bak/$ (date +%f_%h%m)
if [!-d "$mysql _db_bak"];
Then
Mkdir-p $mysql _db_bak
Fi
# define WWW backup path
www_src_bak= $basedir/www_src_bak/$ (date +%f_%h%m)
if [!-d "$www _src_bak"];
Then
Mkdir-p $www _src_bak
Fi
# Backup files
mysql_bak= $mysql _db_bak/test.sql.gz
www_bak= $www _src_bak/www.rar
www_bak_part1= $www _src_bak/www.part1.rar
www_bak_part2= $www _src_bak/www.part2.rar
www_bak_part3= $www _src_bak/www.part3.rar
# define Attachment Array
all_bak= ($mysql _bak $www _bak_part1 $www _bak_part2 $www _bak_part3)
# message Headers
mail_subject= "Showerlee.com_and_yanwenbo.cn_daily_backup"
# message Content
Mail_content_mysql= "Send Mysql_bak at $ (date +%f_%h%m)"
mail_content_www_p1= "Send Www_src rarball part1 at $ (date +%f_%h%m)"
mail_content_www_p2= "Send Www_src Rarball part2 at $ (date +%f_%h%m)"
mail_content_www_p3= "Send Www_src rarball part3 at $ (date +%f_%h%m)"
# define an array of content
Mail_content= ("$mail _content_mysql" "$mail _content_www_p1" "$mail _content_www_p2" "$mail _content_www_p3")
# Mail Address
mail_address1= "Showerlee@vip.qq.com"
Mail_address2= "Kevinywb@vip.qq.com"
# 1. Back up MySQL
Mysqldump-u $user-p$passwd--opt--skip-lock-tables--flush-logs--database Test | gzip > $mysql _bak
# 2. Back up the WWW source code (split several 45m of tar packets)
If [-Z $rar];then
Exit 0
Fi
Cd/data
RAR a-v45000k $www _bak www
# 3. Send Attachments
for ((i=0; i!=${#all_bak [@]}; ++i))
{
If [f ${all_bak[i]}]; Then
echo ${mail_content[i]} | Mutt-s $mail _subject $mail _address1 $mail _address2-a ${all_bak[i]}
Else
echo ${mail_content[i]} | Mutt-s $mail _subject $mail _address1 $mail _address2-a $www _bak
Break
Fi
}
# 4. Clean up mutt temporary files
Cat/dev/null > ~/sent
# 5. Clean up the backup files 1 months ago
dir=/data/backup/daily/
Find $dir-mtime +30-type d-name "201*"-print |xargs-i \ Rm-rf {} 2>/dev/null
# 6. Free System Cache
Echo 1 >/proc/sys/vm/drop_caches
--------------------------------------------------------
Note: If you report the following error
------------------
Postdrop:warning:uid=0:file too large
Sendmail:fatal:root (0): Message file too
The Error sending message, the child exited (Deferred.).
Could not send the message.
------------------
is due to exceeding the system default send attachment size, modified to the following size can be (2G)
# postconf-e "Message_size_limit = 2048000000"
# postconf-e "Mailbox_size_limit = 2048000000"
3. Execute script
# sh/etc/rc.d/mail_to_bak_daily.sh
Note: You can use tail-f/var/log/maillog to view send logs

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.