/
upload-methods.sh
107 lines (90 loc) · 3.04 KB
/
upload-methods.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright (C) 2005 The Backup Manager Authors
#
# See the AUTHORS file for details.
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# This is upload methods library.
# Reads the configuration keys in order to set the
# environement (hosts, sources, ...)
bm_upload_init()
{
hosts="$1"
bm_upload_hosts=$(echo $hosts| sed -e 's/ /,/g')
v_switch=""
if [ "$verbose" == "true" ]; then
v_switch="-v"
fi
}
# Manages SSH uploads
bm_upload_ssh()
{
info "Using the upload method \"ssh\"."
bm_upload_hosts="$BM_UPLOAD_HOSTS $BM_UPLOAD_SSH_HOSTS"
bm_upload_init "$bm_upload_hosts"
if [ -z "$BM_UPLOAD_SSH_DESTINATION" ]; then
BM_UPLOAD_SSH_DESTINATION="$BM_UPLOAD_DESTINATION"
fi
if [ -z "$BM_UPLOAD_SSH_DESTINATION" ]; then
error "No valid destination found, SSH upload not possible."
fi
# the flags for the SSH method
k_switch=""
if [ ! -z "$BM_UPLOAD_SSH_KEY" ]; then
k_switch="-k=\"$BM_UPLOAD_SSH_KEY\""
fi
# Call to backup-manager-upload
su $BM_UPLOAD_SSH_USER -s /bin/sh -c \
"$bmu $v_switch \
$k_switch \
-m=\"scp\" \
-h=\"$bm_upload_hosts\" \
-u=\"$BM_UPLOAD_SSH_USER\" \
-d=\"$BM_UPLOAD_SSH_DESTINATION\" \
-r=\"$BM_REPOSITORY_ROOT\" today" ||
error "Unable to call backup-manager-upload."
}
# Manages FTP uploads
bm_upload_ftp()
{
info "Using the upload method \"ftp\"."
bm_upload_hosts="$BM_UPLOAD_HOSTS $BM_UPLOAD_FTP_HOSTS"
bm_upload_init "$bm_upload_hosts"
if [ -z "$BM_UPLOAD_FTP_DESTINATION" ]; then
BM_UPLOAD_FTP_DESTINATION="$BM_UPLOAD_DESTINATION"
fi
if [ -z "$BM_UPLOAD_FTP_DESTINATION" ]; then
error "No valid destination found, FTP upload not possible."
fi
# flags for the FTP method
ftp_purge_switch=""
if [ "$BM_UPLOAD_FTPPURGE" == "yes" ] ||
[ "$BM_UPLOAD_FTPPURGE" = "true" ]; then
ftp_purge_switch="--ftp-purge"
fi
$bmu $v_switch $ftp_purge_switch \
-m="ftp" \
-h="$bm_upload_hosts" \
-u="$BM_UPLOAD_FTP_USER" \
-p="$BM_UPLOAD_FTP_PASSWORD" \
-d="$BM_UPLOAD_FTP_DESTINATION" \
-r="$BM_REPOSITORY_ROOT" today ||
error "unable to call backup-manager-upload"
}
# Manages RSYNC uploads
bm_upload_rsync()
{
error "The upload method \"rsync\" is not supported."
}