-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup-ftp
More file actions
executable file
·55 lines (50 loc) · 1.23 KB
/
Copy pathbackup-ftp
File metadata and controls
executable file
·55 lines (50 loc) · 1.23 KB
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
#!/bin/bash
INFO="
Use 'lftp' to download a snapshot of a remote FTP directory.
Usage:
backup-ftp -u <user> -p <password> [ -o <outfile.tgz> ] host
"
if test -z "$1"; then
echo "$INFO" 1>&2
exit 1
fi
TMPDIR=$(mktemp -d) || exit 1
trap "rm -rf $TMPDIR" EXIT
USER=
PASS=
while test -n "$1"; do
FILE=
while getopts "u:p:" opt; do
case "$opt" in
u) USER="$OPTARG" ;;
p) PASS="$OPTARG" ;;
o) FILE="$OPTARG" ;;
*) exit 1 ;;
esac
done
shift $(($OPTIND - 1))
HOST="$1"
shift
if test -z "$HOST"; then
echo "Error: No host specified!" 1>&2
exit 1
fi
test -n "$FILE" || FILE="ftp-$HOST-$(date '+%Y-%m-%d').tgz"
if test -e "$FILE"; then
echo "Warning: Skipping '$FILE'" 1>&2
continue
fi
if test -e "$FILE"; then
echo "Error: '$FILE.NEW' exits!" 1>&2
exit 1
fi
rm -rf "$TMPDIR/mirror" || true
mkdir "$TMPDIR/mirror" || exit 1
CMD="mirror --parallel=10 . $TMPDIR/mirror"
echo "$CMD" | lftp -u "$USER,$PASS" "$HOST" || exit 1
if ! tar -C "$TMPDIR/mirror" -c . | gzip > "$FILE.NEW"; then
rm "$FILE.NEW"
exit 1
fi
mv "$FILE.NEW" "$FILE" || exit 1
done