How to backup your website data with Android phone

No matter what you do, backup is very necessary and important. Backup is just in case. Most of the time, people don’t need these backup things. After a period of backup, many people have a sense of paralysis and begin to stop the backup. Often at this time, once the server or hard disk goes wrong or is deleted by mistake, there is no place to cry.

The data can be backed up to the local machine, which can resist the data loss caused by misoperation and deletion. But how to make the hard disk have problems, the local machine backup will not work. The most secure backup method is remote backup, that is, backup to another machine. This requires two servers to perform the backup every night. In two days, the machines can backup each other.

Most webmasters have only one server, or even a virtual host. In this case, if you want to backup in other places, you can only backup to your desktop or notebook at home. Manual backup is very troublesome, while automatic backup – home computers can’t be backed up in the morning all year round without shutting down, which costs electricity and damages skills. If you think about it from another angle, in fact, every family has several servers that don’t turn off 24 hours a year – your smart phones. A small mobile phone, if you install Linux system in it, becomes a powerful server. In the last article, I introduced how to install Linux system in Android mobile phone. Next, I will introduce how to back up your website data with mobile phone.

(this article takes WordPress website as an example, other websites can refer to)

General personal website need to backup data are: 1) program, 2) database, 3) data file (picture). First of all, the program is stored in GitHub or bitsocket, which is very safe and does not need to be backed up. What needs to be backed up is the database and picture files.

Generally, the amount of data in the personal website database is not very large. After several hundred megabytes of database files are exported and compressed, it is less than 50 megabytes. Previously, I introduced how to automatically back up the script of MySQL database every day. Another shell script is deployed in the Linux server of the mobile phone to pull the execution file every day.

#!/bin/bash

	DBNAME=dbname
	DATE=`date +"%Y%m%d"`
	SQLFILE=ftp://your-host-ip/$DBNAME-${DATE}.sql.gz
	wget --ftp-user=usr --ftp-password=yourpassword --directory-prefix=/backup-dir $SQLFILE

This script on can pull the database files that you back up by date every day to the local.

All that’s left is a backup image. Because the image data is very large, it may be several G in size, so we have to use incremental backup. We only backup the new files of the day every day, and do a full backup manually every other period of time, such as three months, to clear the incremental files in the mobile phone, which does not occupy the storage space of the mobile phone. The following script is to find out the new image files added every day on the website server and generate a file list:

#!/bin/bash
        FILEDIR=`date --date="1 days ago" +"%Y/%m"`
	find /server/public_html/wordpress/wp-content/uploads/$FILEDIR/* -mtime -1 -exec sh -c ' name={}; name=${name#*html};echo http://your-website.com/your-web-root/$name' ;  > /backup-dir/image-list.txt

The above script generates an image every day- list.txt File, which stores the HTTP path of the image file added the previous day. We will deploy another script in the Linux server of the mobile phone to grab this file, and then grab the pictures listed in the file to the local, and store them in the original directory.

#!/bin/bash
       DATE=`date --date="1 days ago" +"%Y/%m"`

	images_path=/mobile-backup-dir/uploads/${DATE}
	wget http://your-website.com/path/image-list.txt
	wget -i image-list.txt  --directory-prefix=$images_path
	#wget -i $filename --directory-prefix=$images_path
	rm image-list.txt

The above backup schemes are suitable for personal websites (the amount of data is not particularly large). Take WordPress website framework as an example. If it is a virtual host, you may not have permission to place a timed cron execution script on the virtual host. You can use PHP to generate related files. The script on the server and the script in the mobile Linux are executed in the early morning. Backup and pull the data of the previous day. The script of backup data must be executed before the script of pull data, and the time sequence should be well controlled. It only takes a few minutes to pull 30 megabytes (150 megabytes before compression) plus 100 new pictures into the mobile phone. Nowadays, the storage space of the mobile phone is generally 32g / 64g, and there is some space.

Since the advent of smart phones, many previously impossible things can be done, such as didi taxi, bike sharing, shopping without money and so on. Today’s talk about using mobile phones as servers to perform backup tasks is also true. For programmers, there are still many things they can do on smart phones, which need to be explored slowly.

Related Article
WordPress 3D rotating tag cloud

This 3D tag cloud is not the flash version of WP cumulus n years ago. This 3D rotating tag cloud Read more

Using wampserver tool to build local PHP + MySQL environment

No matter whether we use domestic space or foreign hosts, we prefer to go online after local debugging before setting Read more

How to install Linux system on Android phone

In our daily use of Android mobile phones, the installation of a complete Linux system will make mobile phones become Read more

What technology is PHP composer?

If you are a programmer, you are likely to find that the wheel of technology update is too fast for Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image