From 0e229a15e26c40a5b95f23129874eb0399b468d9 Mon Sep 17 00:00:00 2001 From: SemvdH Date: Tue, 26 Aug 2025 22:13:55 +0200 Subject: [PATCH] Add scripts for backing up --- start-backup.sh | 36 ++++++++++++++++++++++++++++++++++++ stop-backup.sh | 5 +++++ tar-and-backup-service.sh | 20 ++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 start-backup.sh create mode 100644 stop-backup.sh create mode 100644 tar-and-backup-service.sh diff --git a/start-backup.sh b/start-backup.sh new file mode 100644 index 0000000..415f747 --- /dev/null +++ b/start-backup.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +if [ $# -ne 0 ] +then + echo "Running backup $1 script at $(date)" +else + echo "Running backup script at $(date)" +fi + +echo "running backup $SERVICE script at $(date)" + +is_online="offline" + +if ping -W 1 -c 1 10.10.100.52 > /dev/null 2>&1; then + is_online="online" +fi + +echo "sending start command" +curl "http://10.10.100.12:8123/startbackup" + +if [ "$is_online" = "online" ]; then + echo "VM already online" +else + echo "backups VM is offline!" + echo "waiting 30 seconds for the VM to start up..." + sleep 30 +fi + +is_online_after_cmd=$(ping -W 1 -c 1 10.10.100.52) +if [ "$?" == "1" ]; then + echo "Backups VM is still offline!" + curl "http://10.10.100.12:8123/stopbackup" + exit 1 +fi + +echo "backups VM is online! Continuing with backup" \ No newline at end of file diff --git a/stop-backup.sh b/stop-backup.sh new file mode 100644 index 0000000..dc9392a --- /dev/null +++ b/stop-backup.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "backup done!" +echo "shutting down backups vm" +curl "http://10.10.100.12:8123/stopbackup" \ No newline at end of file diff --git a/tar-and-backup-service.sh b/tar-and-backup-service.sh new file mode 100644 index 0000000..034b49b --- /dev/null +++ b/tar-and-backup-service.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# script to tar a folder and rsync it to backup server + +if [ -z "$1" ] + then + echo "No argument supplied. Supply argument of folder name to backup" + exit 0 +fi + +BACKUP_FOLDER=$1 +TAR_FILE=$BACKUP_FOLDER.tar.gz + +echo " == Backing up $1 to $TAR_FILE" +echo " == Creating tar.gz file" +tar czvf $TAR_FILE /home/sem/$BACKUP_FOLDER +echo " == transfering tar file" +rsync -avz --stats --progress $TAR_FILE sem@10.10.100.52:/home/sem/$BACKUP_FOLDER/ +echo " == Removing local tar file" +rm $TAR_FILE \ No newline at end of file