aboutsummaryrefslogtreecommitdiff
path: root/backends/tar.sh
diff options
context:
space:
mode:
Diffstat (limited to 'backends/tar.sh')
-rw-r--r--backends/tar.sh49
1 files changed, 45 insertions, 4 deletions
diff --git a/backends/tar.sh b/backends/tar.sh
index 4d7ff36..c6012e3 100644
--- a/backends/tar.sh
+++ b/backends/tar.sh
@@ -1,14 +1,55 @@
+function tar_init() {
+ # nothing to do for tar?
+ :
+}
+
# TODO: Make default .tar with optional bup
function tar_create_backup() {
- ARCHNAME="backup/$WORLD_NAME-backup_`date +%d-%m-%y-%T`.tar.gz"
+ echo "tar: backing up..."
+
+ # save world to a temporary archive
+ ARCHNAME="/tmp/${BACKUP_NAME}_`date +%d-%m-%y-%T`.tar.gz"
tar -czf "$ARCHNAME" "./$WORLD_NAME"
if [ ! $? -eq 0 ]
then
- echo "TAR failed. No Backup created."
- rm $ARCHNAME #remove (probably faulty) archive
+ echo "tar: failed to save the world"
+ rm "$ARCHNAME" #remove (probably faulty) archive
return 1
else
- echo $ARCHNAME created.
+ echo "tar: world saved to $ARCHNAME, pushing it to backup directories..."
fi
+
+ RETCODE=2
+ 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/"
+ if [ ! $? -eq 0 ]; then
+ echo "tar: failed pushing to \"$BACKUP_DIR\", moving on"
+ else
+ RETCODE=0
+ fi
+ done
+
+ rm "$ARCHNAME"
+
+ echo "tar: backup finished"
+
+ return $RETCODE
+}
+
+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
+ done
}