Last active
November 1, 2016 03:32
-
-
Save chusiang/b2e026d755eb9a627d153ec7d8638226 to your computer and use it in GitHub Desktop.
Clone all files from bucket1 to bucket2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ============================================================ | |
# Author: Chu-Siang Lai / chusiang (at) drx.tw | |
# Blog: http://note.drx.tw | |
# Filename: clone-qiniu-bucket.sh | |
# Modified: 2016-11-01 11:06 | |
# Description: Clone all files from bucket1 to bucket2. | |
# | |
# $ chmod +x clone-qiniu-bucket.sh | |
# $ ./clone-qiniu-bucket.sh bucket_source bucket_new | |
# | |
# Reference: | |
# | |
# - qiniu/qshell: qshell 是利用七牛文档上公开的 API 实现的一个方便开发者测试和使用七牛 API 服务的命令行工具。 | |
# - https://github.com/qiniu/qshell | |
# - listbucket · qiniu/qshell Wiki | |
# - https://github.com/qiniu/qshell/wiki/listbucket | |
# - batchcopy · qiniu/qshell Wiki | |
# - https://github.com/qiniu/qshell/wiki/batchcopy | |
# | |
# =========================================================== | |
## Init | |
# | |
BUCKET_SRC="$1" | |
BUCKET_NEW="$2" | |
# Create the `tmp` directory. | |
if [ ! -d "tmp/" ]; then | |
mkdir "tmp/"; | |
fi | |
## Original | |
# | |
# List files under original bucket. | |
qshell listbucket $BUCKET_SRC tmp/$BUCKET_SRC.list.txt | |
# count. | |
ORI_BUCKET_STATUS=$(wc -l tmp/$BUCKET_SRC.list.txt | awk '{ print $1 }') | |
# Filier the filenames. | |
cat tmp/$BUCKET_SRC.list.txt | awk '{ print $1 }' > tmp/$BUCKET_SRC.onlyfilenamelist.txt | |
## Clone | |
# | |
# Clone with batchcopy, and we need manual input the verification code. | |
time qshell batchcopy $BUCKET_SRC $BUCKET_NEW tmp/$BUCKET_SRC.onlyfilename.list.txt | |
## New | |
# | |
# List files under new bucket. | |
qshell listbucket $BUCKET_NEW tmp/$BUCKET_NEW.list.txt | |
# count. | |
NEW_BUCKET_STATUS=$(wc -l tmp/$BUCKET_NEW.list.txt | awk '{ print $1 }') | |
## Result | |
# | |
echo "File number of original bucket: " $ORI_BUCKET_STATUS | |
echo "File number of new bucket: " $NEW_BUCKET_STATUS | |
## Clean | |
# | |
#if [ -d "tmp/" ]; then | |
# rm -f "tmp/*.txt" && rmdir tmp/ | |
#fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment