background

Recently I received two emails from Qiuniyun:

Test domain name recall notification

Your account XXX has the following test domain name in qiniuyun Fusion CDN acceleration platform, and the remaining 7 natural days will be automatically recovered by the system

Because, my blog all picture files are stored in seven niuyun, this domain name has been used for more than a year, how suddenly want to recycle it?

A search on the Internet only to know that there are probably some lawbreakers and so on, using seven niuyun free space to spread content such as pornography and violence, was sanctioned by Godday, now the new application bucket can only be used for a month, to bind the domain name, but also have to put on record operation. An this small blog, also play with respect to oneself of a foreign server, also prepare case.

Helpless, see a lot of people on the Internet are recycled just know their pictures are not accessible. Thankfully, I’m used to looking at these push emails and have given myself a week to backup and transfer. Since the free is not good to use, such as weibo map bed is not good migration, so I bought a year ali Cloud OSS service.

Although my pictures are not very many, but if a manual download and then upload ali Cloud, is not a small amount of work, and it is a waste of time.

So today, I spent some time to write an automatic migration tool (move_qiniuyun_to_ALIOSS) and open source it to GitHub. There is no complicated operation, just take down the image and back up the data locally. Then upload directly to the specified bucket through ali Cloud API interface.

Because of the small amount of data, there is no consideration for FIFO, asynchronous and so on (see the situation later to optimize, everything is demand-oriented).

Although small, I wanted to be as generic as possible, so I pulled all the configuration parameters into the config.py file. Each person according to their own configuration modification, directly available.

The following is a tutorial on unix-like systems

The preparatory work

Use qshell-Darwin-x64 in the tool/ directory:

Note: Please refer to:Github.com/qiniu/qshel…

  • Configure the account to access the Bull cloudaccess_keysecret_key
  • Pull up a list of files for the seven Cloud buckets to move:
# need to set the AK, SK of seven niuyun first
Access the address https://portal.qiniu.com/user/key #
./tool/qshell-darwin-x64 account ak sk
# are file names generated by bucket_name
./tool/qshell-darwin-x64 listbucket2 vimiix-blog-data listbucket.txt
Copy the code

A listbucket.txt file will be generated in the current directory, and the work is ready.

Modifying a Configuration File

Set each parameter to its own value according to the comments in the config file.

  • AliOss AccessKeyID and AccessKeySecret get the address
    • usercenter.console.aliyun.com/#/manage/ak

perform

This tool uses the oss2 package of ali cloud. It needs to be larger than version 3, but it says on the official website that Python3.5 is supported at most

So my virtual environment also uses Python3.5, I recommend you do the same, save the trouble.

Create a virtual environment, do not need to isolate the environment, can directly install dependencies on the system version 3Virtualenv - python = python3.5 venv - no - site - packageActivate the virtual environment
source venv/bin/activate

Install dependencies
pip install -r pip-req.txt

# to perform
python main.py
Copy the code

The execution result

And you’re done!

The project address

  • Github.com/vimiix/move…

— EOF —