blob: f7ea86e6aa1c63e2e0be66022437b01f16dd510b (
plain)
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
|
function tar_init() {
# nothing to do for tar?
:
}
# TODO: Make default .tar with optional bup
function tar_create_backup() {
echo "tar: backing up..."
local status
# save world to a temporary archive
local archname="/tmp/${BACKUP_NAME}_`date +%FT%H%M%S%z`.tar.gz"
tar -czf "$archname" "./$WORLD_NAME"
status=$?
if [ $status -ne 0 ]; then
echo "tar: failed to save the world"
rm "$archname" #remove (probably faulty) archive
return 1
fi
echo "tar: world saved to $archname, pushing it to backup directories..."
# 0 if could save to at least one backup dir
# TODO: make more strict?
local retcode=1
for backup_dir in ${BACKUP_DIRS[*]}
do
echo "tar: pushing to \"$backup_dir\""
# scp acts as cp for local destination directories
scp "$archname" "$backup_dir/"
status=$?
if [ $status -ne 0 ]; then
echo "tar: failed pushing to \"$backup_dir\", moving on"
else
retcode=0
fi
done
rm "$archname"
echo "tar: backup finished"
return $retcode
}
# server_restore relies on output format of this function
function tar_ls_dir() {
local backup_dir="$1"
if [[ "$backup_dir" == *:* ]]; then
local remote="$(echo "$backup_dir" | cut -d: -f1)"
local remote_dir="$(echo "$backup_dir" | cut -d: -f2)"
ssh "$remote" "ls -1 $remote_dir" | grep "tar.gz" | sort -r
else
ls -1 "$backup_dir" | grep "tar.gz" | sort -r
fi
}
function tar_ls_all() {
for backup_dir in ${BACKUP_DIRS[*]}
do
echo "tar: backups in ${backup_dir}:"
tar_ls_remote "$backup_dir"
done
}
function tar_restore() {
local remote="$1"
local snapshot="$2"
local status
scp "$remote/$snapshot" "/tmp/"
status=$?
if [ $status -ne 0 ]; then
echo "tar: failed to get archive from \"$remote/$snapshot\""
return 1
fi
tar -xzf "/tmp/$snapshot"
}
|