Add scripts for backing up

This commit is contained in:
SemvdH
2025-08-26 22:13:55 +02:00
parent e4f7d0fd8c
commit 0e229a15e2
3 changed files with 61 additions and 0 deletions

36
start-backup.sh Normal file
View File

@@ -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"

5
stop-backup.sh Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
echo "backup done!"
echo "shutting down backups vm"
curl "http://10.10.100.12:8123/stopbackup"

20
tar-and-backup-service.sh Normal file
View File

@@ -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