update and cleanup

This commit is contained in:
Tomislav Kopić 2024-02-09 22:15:49 +01:00
parent a85701eee2
commit a315989db1
5 changed files with 26 additions and 101 deletions

View File

@ -1,53 +0,0 @@
#!/bin/sh
# Borg repo location
REPOSITORY=/var/backup/database.borg/
# Example of remote repo
# REPOSITORY=ssh://backuper@192.168.1.100/var/backup/database.borg/
borgDoBackup() {
sudo -u postgres pg_dumpall > /var/backups/posgresql.sql
borg create -v --stats --compression zlib,6 $REPOSITORY::`date +%Y-%m-%d-%H:%M` /var/backups/posgresql.sql
rm /var/backups/posgresql.sql
borg prune -v $REPOSITORY --keep-daily=3 --keep-weekly=2 --keep-monthly=12
echo "`date +[%F/%T]` Done!"
}
repoid=$(grep "id" $REPOSITORY/config | awk '{print $3}')
procid=$(pgrep borg | tail -1)
if [ -d $REPOSITORY/lock.exclusive ] || [ -d /root/.cache/borg/$repoid/lock.exclusive ]; then
if [ ! -z $procid ]; then
echo "`date +[%F/%T]` Seems like the borg repo is busy at the moment, I will try again in 30 min"
at now + 30 minutes -f $0
exit
else
if [ -d $REPOSITORY/lock.exclusive ]; then
rm -r $REPOSITORY/lock.*
fi
if [ -d /root/.cache/borg/$repoid/lock.exclusive ]; then
rm -r /root/.cache/borg/$repoid/lock.*
fi
borgDoBackup
fi
else
borgDoBackup
fi
exit

View File

@ -1,53 +1,15 @@
#!/bin/sh
#!/bin/bash
# Borg repo location
REPOSITORY=/var/backup/files.borg/
# Example of remote repo
# REPOSITORY=ssh://backuper@192.168.1.100/var/backup/files.borg/
borgDoBackup() {
echo "`date +[%F/%T]` Starting the backup"
borg create -v --compression lzma,6 --stats $REPOSITORY::`date +%Y-%m-%d-%H:%M` /etc/ /var/www/ /var/spool/ --exclude=*.log
borg prune -v $REPOSITORY --keep-daily=3 --keep-weekly=2 --keep-monthly=12
echo "`date +[%F/%T]` Done!"
}
repoid=$(grep "id" $REPOSITORY/config | awk '{print $3}')
procid=$(pgrep borg | tail -1)
if [ -d $REPOSITORY/lock.exclusive ] || [ -d /root/.cache/borg/$repoid/lock.exclusive ]; then
if [ ! -z $procid ]; then
echo "`date +[%F/%T]` Seems like the borg repo is busy at the moment, I will try again in 30 min"
at now + 30 minutes -f $0
exit
else
if [ -d $REPOSITORY/lock.exclusive ]; then
rm -r $REPOSITORY/lock.*
fi
if [ -d /root/.cache/borg/$repoid/lock.exclusive ]; then
rm -r /root/.cache/borg/$repoid/lock.*
fi
borgDoBackup
fi
else
borgDoBackup
fi
echo "`date +[%F/%T]` Starting the backup"
# Create backup
borg create -v --compression lzma,6 --stats $REPOSITORY::$(date +%Y-%m-%d-%H:%M) /etc/ /var/www/ /var/spool/ --exclude=*.log
# Clean old backups
borg prune -v $REPOSITORY --keep-daily=3 --keep-weekly=2 --keep-monthly=12
echo "`date +[%F/%T]` Done!"
exit

17
borg-postgresql-backup.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# Borg repo location
REPOSITORY=/var/backup/database.borg/
# Example of remote repo
# REPOSITORY=ssh://backuper@192.168.1.100/var/backup/database.borg/
# Dump all postgres databases to file
sudo -u postgres pg_dumpall > /tmp/posgresql.sql
# Backup the sql file
borg create -v --stats --compression zlib,6 $REPOSITORY::$(date +%Y-%m-%d-%H:%M) /tmp/posgresql.sql
rm /tmp/posgresql.sql
# Delete old backups
borg prune -v $REPOSITORY --keep-daily=3 --keep-weekly=2 --keep-monthly=12
echo "`date +[%F/%T]` Done!"
exit

View File

@ -1,5 +1,6 @@
#!/bin/bash
# Ment to be run on a remote backup server to run prune on all repos
borgRepos=$(find ~/path/to/backups/ -type d -name "*.borg")
for REPOSITORY in ${borgRepos}; do
@ -7,4 +8,4 @@ for REPOSITORY in ${borgRepos}; do
done
exit
exit

View File

@ -20,8 +20,6 @@ if host $dnsrecord 1.1.1.1 | grep "has address" | grep "$ip"; then
exit
fi
# if here, the dns record needs updating
# get the zone id for the requested zone
zoneid=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone&status=active" \
-H "X-Auth-Email: $cloudflare_auth_email" \