-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-backup-block.sh
executable file
·84 lines (70 loc) · 2.35 KB
/
upload-backup-block.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
#
# Copyright (C) 2017 Marek Marecki
#
# This file is part of Viua VM.
#
# Viua VM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Viua VM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Viua VM. If not, see <http://www.gnu.org/licenses/>.
#
set -e
HASHED=$1
# TODO Maybe employ wput to support FTP?
################################################################################
# ONE-BLOCK UPLOADERS HERE
#
function upload_one_block_using_rsync {
rsync --verbose --ignore-existing $1.block $STORAGE_USER@$STORAGE_HOST:$STORAGE_ROOT/blocks/
}
function upload_one_block_using_scp {
scp $1.block $STORAGE_USER@$STORAGE_HOST:$STORAGE_ROOT/blocks/
}
function upload_one_block {
if [[ $B3_TRANSPORT_TOOL == 'scp' ]]; then
upload_one_block_using_scp $1
elif [[ $B3_TRANSPORT_TOOL == 'rsync' ]]; then
upload_one_block_using_rsync $1
fi
rm $1.block
}
################################################################################
# ALL-BLOCK UPLOADERS HERE
#
function upload_all_blocks_using_rsync {
rsync --verbose --ignore-existing *.block $STORAGE_USER@$STORAGE_HOST:$STORAGE_ROOT/blocks/
}
function upload_all_blocks_using_scp {
scp *.block $STORAGE_USER@$STORAGE_HOST:$STORAGE_ROOT/blocks/
}
function upload_all_blocks {
if [[ $B3_TRANSPORT_TOOL == 'scp' ]]; then
upload_all_blocks_using_scp $1
elif [[ $B3_TRANSPORT_TOOL == 'rsync' ]]; then
upload_all_blocks_using_rsync $1
fi
rm *.block
}
################################################################################
# ENTRY POINT HERE
#
if [[ $B3_UPLOAD_BATCH_SIZE == '' ]]; then
B3_UPLOAD_BATCH_SIZE=0
fi
cd $B3_TMP_DIR
if [[ $B3_UPLOAD_BATCH_SIZE -eq 0 ]]; then
upload_one_block $HASHED
elif [[ $B3_UPLOAD_BATCH_SIZE -lt $(ls -1 *.block | wc -l) ]]; then
upload_all_blocks
elif [[ $B3_UPLOAD_FINISHING == 'yes' ]]; then
upload_all_blocks
fi