aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorGravatar TheMightyV <themightyv@protonmail.com> 2022-01-02 20:12:27 +0100
committerGravatar TheMightyV <themightyv@protonmail.com> 2022-01-02 20:12:27 +0100
commitde4fc74d50d536f524aa4c65e270123bfe8ef893 (patch)
tree977cda9219a434d5d4f8618fc7accde7cb7ef7d3 /backends
parent4baf9150016177582dd56a1bf3c09a3cad5aa050 (diff)
downloadminecraft-server-tools-de4fc74d50d536f524aa4c65e270123bfe8ef893.tar.gz
added backup restoration
Diffstat (limited to 'backends')
-rw-r--r--backends/borg.sh16
-rw-r--r--backends/bup.sh11
-rw-r--r--backends/tar.sh34
3 files changed, 52 insertions, 9 deletions
diff --git a/backends/borg.sh b/backends/borg.sh
index d3d9c63..999067f 100644
--- a/backends/borg.sh
+++ b/backends/borg.sh
@@ -19,7 +19,7 @@ function borg_create_backup() {
echo "borg: starting backup to \"$BACKUP_DIR\""
borg create \
- "${BACKUP_DIR}::${BACKUP_NAME}_{hostname}_{now}" \
+ "${BACKUP_DIR}::${BACKUP_NAME}_$(date +'%F_%H-%M-%S')" \
"$WORLD_NAME" \
--filter AME \
--compression lz4 \
@@ -56,6 +56,11 @@ function borg_create_backup() {
return $RETCODE
}
+function borg_ls_remote() {
+ export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND"
+ borg list "$1" | cut -d' ' -f1
+}
+
function borg_ls() {
export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND"
for BACKUP_DIR in ${BACKUP_DIRS[*]}
@@ -64,3 +69,12 @@ function borg_ls() {
borg list "$BACKUP_DIR"
done
}
+
+function borg_restore() {
+ export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND"
+ REMOTE="$1"
+ SNAPSHOT="$2"
+
+ export BORG_REPO="$REMOTE"
+ borg extract "${REMOTE}::${SNAPSHOT}"
+}
diff --git a/backends/bup.sh b/backends/bup.sh
index e51aaf1..ab27825 100644
--- a/backends/bup.sh
+++ b/backends/bup.sh
@@ -54,6 +54,10 @@ function bup_create_backup() {
return $RETCODE
}
+function bup_ls_remote() {
+ bup -d "$(bup_local)" ls -r "$BACKUP_DIR" "$BACKUP_NAME"
+}
+
function bup_ls() {
for BACKUP_DIR in ${BACKUP_DIRS[*]}
do
@@ -61,3 +65,10 @@ function bup_ls() {
bup -d "$(bup_local)" ls -r "$BACKUP_DIR" --human-readable -l "$BACKUP_NAME"
done
}
+
+function bup_restore() {
+ REMOTE="$1"
+ SNAPSHOT="$2"
+
+ bup -d "$(bup_local)" restore -r "$REMOTE" "$BACKUP_NAME/$SNAPSHOT/$PWD/."
+}
diff --git a/backends/tar.sh b/backends/tar.sh
index c6012e3..b556798 100644
--- a/backends/tar.sh
+++ b/backends/tar.sh
@@ -8,7 +8,7 @@ function tar_create_backup() {
echo "tar: backing up..."
# save world to a temporary archive
- ARCHNAME="/tmp/${BACKUP_NAME}_`date +%d-%m-%y-%T`.tar.gz"
+ ARCHNAME="/tmp/${BACKUP_NAME}_`date +%FT%H%M%S%z`.tar.gz"
tar -czf "$ARCHNAME" "./$WORLD_NAME"
if [ ! $? -eq 0 ]
@@ -40,16 +40,34 @@ function tar_create_backup() {
return $RETCODE
}
+function tar_ls_remote() {
+ BACKUP_DIR="$1"
+ if [[ $BACKUP_DIR == *:* ]]; then
+ REMOTE="$(echo "$BACKUP_DIR" | cut -d: -f1)"
+ REMOTE_DIR="$(echo "$BACKUP_DIR" | cut -d: -f2)"
+ ssh "$REMOTE" "ls -1 $REMOTE_DIR" | grep "tar.gz"
+ else
+ ls -1 "$BACKUP_DIR" | grep "tar.gz"
+ fi
+}
+
function tar_ls() {
for BACKUP_DIR in ${BACKUP_DIRS[*]}
do
echo "Backups in $BACKUP_DIR:"
- if [[ $BACKUP_DIR == *:* ]]; then
- REMOTE="$(echo "$BACKUP_DIR" | cut -d: -f1)"
- REMOTE_DIR="$(echo "$BACKUP_DIR" | cut -d: -f2)"
- ssh "$REMOTE" "ls -1sh $REMOTE_DIR" | grep "tar.gz"
- else
- ls -1sh "$BACKUP_DIR" | grep "tar.gz"
- fi
+ tar_ls_remote "$BACKUP_DIR"
done
}
+
+function tar_restore() {
+ REMOTE="$1"
+ SNAPSHOT="$2"
+
+ scp "$REMOTE/$SNAPSHOT" "/tmp/"
+ if [ ! $? -eq 0 ]; then
+ echo "Failed to get archive from \"$REMOTE/$SNAPSHOT\""
+ return 1
+ fi
+
+ tar -xzf "/tmp/$SNAPSHOT"
+}