马孔多不下雪

Head Pic: 「miku 无视」/「千夜QYS3」のイラスト [pixiv]

At the begining

It’s obvious that a backup work has great significance for something lost or damaged.

I did got my data back via a backup when I accidently deleted the database.

The way to backup

We need to prepare a second copy of a file, program, database, etc, that can be used if the main one fails.

There are two ways to make a copy of your files: the one is exporting automatically; the other is typing every command by hands.

I chose the former. Though it has a little bit difficulty at first.

The way to download the backup files

  • Download it from VPS directly
  • Use a backend storage server
    Both of them has its advantages and disadvantages.
    If you download your files directly from a VPS, the speed will be limited by the bandwidth between the VPS and your computer.(Servers in mainland China usually has only 1M for free, while in US, that can up to 1G.)
    So, If your server was located in mainland China, I’ll advise you to choose the latter way.
    No bandwidth limited and it just cost a little.

Let’s do it

Using Alibaba cloud’s Object Storage Server(oss) as an example.

Step 1: Mount

The first thing you need to do is that mount the oss on your server via ossfs.
More information about the ossfs, please go to this page.
Having completed the first stage, you can move onto Step 2.

Step 2: Script

Write a script like this:

1
2
3
4
5
#!/bin/bash
tar -czvf `date +"%Y%m%d"`_xxxx.tar.gz xxxx
mysqldump -uroot -p***** --all-databases > localhost.sql
tar -czvf `date +"%Y%m%d"`_database.tar.gz localhost.sql
mv `date +"%Y%m%d"`* /home/backup/ossfs/

/home/backup/ossfs is a directory where the oss mounted.

Step 3: Download

Go to oss control panel to download your files.