Dropbox automatic backup script for WP space

Source: Internet
Author: User
Tags date mkdir pack version ssh dropbox automatic backup backup linux

If your space is a Linux system, the space is relatively large, with SSH permissions, so congratulations, you can use this script to achieve automatic backup of the entire WP to space or Dropbox on.

The script dobackwebsite.sh uses the Linux crontab function to realize the automatic timing backup function, and automatically deletes the expired backup file, saves the space, Cheng thinks that deletes the three days before the backup script, certainly you can make in the script automatically;-), below describes the script usage procedure.

1. The contents of the script are as follows

dobackwebsite.sh

#!/bin/bash#*********************************************************## File:doBackWebSite.sh # # Perpose: Automatically backs up and deletes the previous backup files for the specified number of days # Atuthor: Wu Zejun # WEBSITE:WWW.FLY3Q.C Om # date:2010-06-25 # # modify:2010-06-29 Add Dr Opbox Backup Support ##*********************************************************##************************************ # # Local Variable ##*********************************************** # #空间的更目录HOME_DIR = "~" #网站内容放置的文件WS_DIR = "fly3q.com" #放置备份的文件夹BK_DIR = "Back" #Dropbox放置备份的文件夹Dropbox_BK_DIR = "Dropbox/wpback" #Dropbox安装目录Dropbox_BK_DIR = ". Dropbox-dist" #网站备份名字BACK_FILE_NAME = $WS _dir ' date +%y%m%d ' ". tgz" #**     # # function:auto_back_files # # Input   : $ is_back_to_dropbox-whether to back up to Dropbox # #-True/false ##********************************************************* #function Auto_back _files () {CDs ~ IF [!-D $BK _dir];then mkdir-p $BK _dir fi cd $WS _dir tar-czf $BACK _file_name * mv $BACK _file_name. /$BK _dir echo "[OK] back up $BACK _file_name" if [-N $1-a "$" = "true"];then Move_back_to_dropbox fi}#************* # # Function:move_back_to_dropbox # # Input: Back up the site To Dropbox ##********************************************************* #function Move_back_to_dropbo X () {If [-Z ' PS auxawk-f '] ' {print $11} ' grep ' ^/home/[^]*[dropbox] '];then cd ~/$BK _dir/$Dropbox _bk_dir dropboxd &am  P fi if [D-Dropbox];then CD Dropbox if [!-D wpback];then mkdir wpback fi cd ~/$Dropbox _bk_dir cp ~/$BK _dir/$BACK _fil	E_name.  echo "[OK] $BACK _file_name had Benn back to Dropbox." else echo [FAIL] You had not installed dropbox,please the A-install Dropbox. "  fi}#*********************************************************## Function:auto_delete_last_back_files # # Input: offset_day-Automatically delete the backup files specified days ago # #-Default 3 days of backup files deleted ##********************************************* #function Auto_delete_last_back_files () {local year= ' date ' +%y ' the ' local month_of_year= ' date ' +%m ' sed s/^0// ' Local day_of_month= ' date ' +%d ' sed s/^0//' local offest=3 local index=1 local month= (0) Local day= (0) while [$inde  X-le 12];  Do month[$index]= "$index" let Index+=1 did index=1 while [$index-le 31]; Do day[$index]= $index Let index+=1 the Done if [-N "$"];then offest=$1 fi ret_day= let ret_day= $day _of_month-$offes t if [$ret _day-le 9];then If [$ret _day-le 0];then let ret_month= $month _of_year-$ret _day/31-1 if [$ret _month-le 9];then ret_month= "0" $ret _month fi let index=31+ $ret _day%31 ret_day=${day[$index]} if [$ret _day-le 9];then ret	_day= "0" $ret _day fi Else ret_day= "0" $ret _dayfi fi If [n "$ret _month"];then ret_month= ' echo $ret _monthsed s/^0//' ret_month= ' 0 "$ret _month else ret_month=" 0 "$mont H_of_year fi ret_year= $year ret_date= $ret _year$ret_month$ret_day ret_bck_file_name= $WS _dir$ret_date ". tgz" CD ~ CD $B  K_dir if [f $ret _bck_file_name];then #rm-fr $ret _bck_file_name echo "[OK] DELETE $ret _bck_file_name" Else echo  "[FAIL] $ret _bck_file_name not exist!!"		Fi CD ~ if [D-$Dropbox _bk_dir];then CD $Dropbox _bk_dir if [-F $ret _bck_file_name];then #rm-fr $ret _bck_file_name echo [OK] deletes Dropbox backfile-> $ret _bck_file_name. ' Else echo ' [FAIL] Dropbox backfile-> $ret _bck_file_nam E not EXIST. "Fi fi}auto_back_files Trueauto_delete_last_back_files

2. SSH Landing Space

Build a directory back to the directory, put this script into this back directory.

3. Configure Crontab

Input CRONTAB-E, to configure the situation of Linux automatic operation, the specific parameter configuration can refer to another article about crontab.

For example, my configuration is as follows:

* * 1-7 Cd/home/user1/back/;bash dobackwebsite.sh

Represents the ability to perform an automatic backup of a dobackwebsite.sh script every 22:22.

4. Install Dropbox

Dropbox is a cloud storage service that can store files online and provide version-version management. Please refer to http://wiki.dropbox.com for details.

Installation Steps Reference Http://wiki.dropbox.com/TipsAndTricks/TextBasedLinuxInstall

$ cd ~

$ cd Wget-o dropbox.tar.gz http://www.dropbox.com/download/?plat=lnx.x86

$ tar-zxof dropbox.tar.gz

$ mv. dropbox-dist ~

$ cd ~

$ ~/.dropbox-dist/dropboxd &

At this time will prompt a string of URLs, ask you in the browser to enter this string URL will this virtual host connected to the Dropbox, after landing you can see the hint this machine has been connected to the Dropbox.

Note: This is the first time this need to configure this, the system will save the landing state will not need to manually enter the URL, which is also the script to achieve automatic backup to the above key.

Through the PS Auxgrep Dropbox to see if Dropbox has already run up, some words congratulations to you Dropbox configuration succeeded.

5. Complete the configuration

The first time you run dobackwebsite.sh manually, you have finished linking the virtual host to Dropbox.

This automatically backs up your site on a daily basis, and you can view the backup by Ls-oh. At the same time, if the receiving mailbox is configured, the system crontab will automatically send out a message to execute the result.

Cron Cd/home/user1/back/;bash dobackwebsite.sh

[OK] Back Up fly3q.com20100629.tgz

[OK] Fly3q.com20100629.tgz had Benn back to Dropbox.

[OK] DELETE fly3q.com20100626.tgz

[FAIL] Dropbox backfile->fly3q.com20100626.tgz not EXIST.

This side I haven't backed up fly3q.com20100626.tgz to Dropbox so failed, hehe.

At the same time look at the event inside Dropbox can see

6. Summary

This script is completely a hard to pack backup, backup files or put in space, it may be said or not safe, then of course, you can do in your machine to complete the automatic backup remote host files, and then ftp down to the local, so that there is no need to worry about space problems can not be restored in time. This implementation is also very simple, your machine to perform automatic backup, automatic login ssh, everything is done, if necessary, I can share it out.

But take into account our speed problem, the idea is given up, but I think a better way to put on the Microsoft 25G SkyDrive up, but it does not provide the corresponding API Yes, There is only one unofficial. Netapi, if there is a simpler jsapi, if you have any good ideas to welcome the discussion.

Now by Moonlight Blog An article inspiration, I put the backup on the Dropbox, Hehe, also be realized the cloud storage bar. Casually mention the host abroad to upload dropbox speed is fast, I pack the file 60M is basically a minute or so, it is done, envy such a speed.




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.