update and cleanup
This commit is contained in:
parent
a85701eee2
commit
a315989db1
@ -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
|
|
@ -1,53 +1,15 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
# Borg repo location
|
# Borg repo location
|
||||||
REPOSITORY=/var/backup/files.borg/
|
REPOSITORY=/var/backup/files.borg/
|
||||||
# Example of remote repo
|
# Example of remote repo
|
||||||
# REPOSITORY=ssh://backuper@192.168.1.100/var/backup/files.borg/
|
# REPOSITORY=ssh://backuper@192.168.1.100/var/backup/files.borg/
|
||||||
|
|
||||||
|
echo "`date +[%F/%T]` Starting the backup"
|
||||||
borgDoBackup() {
|
# Create backup
|
||||||
|
borg create -v --compression lzma,6 --stats $REPOSITORY::$(date +%Y-%m-%d-%H:%M) /etc/ /var/www/ /var/spool/ --exclude=*.log
|
||||||
echo "`date +[%F/%T]` Starting the backup"
|
# Clean old backups
|
||||||
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
|
||||||
borg prune -v $REPOSITORY --keep-daily=3 --keep-weekly=2 --keep-monthly=12
|
echo "`date +[%F/%T]` Done!"
|
||||||
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
|
exit
|
||||||
|
17
borg-postgresql-backup.sh
Normal file
17
borg-postgresql-backup.sh
Normal 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
|
@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/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")
|
borgRepos=$(find ~/path/to/backups/ -type d -name "*.borg")
|
||||||
for REPOSITORY in ${borgRepos}; do
|
for REPOSITORY in ${borgRepos}; do
|
||||||
|
|
||||||
@ -7,4 +8,4 @@ for REPOSITORY in ${borgRepos}; do
|
|||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
@ -20,8 +20,6 @@ if host $dnsrecord 1.1.1.1 | grep "has address" | grep "$ip"; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if here, the dns record needs updating
|
|
||||||
|
|
||||||
# get the zone id for the requested zone
|
# get the zone id for the requested zone
|
||||||
zoneid=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone&status=active" \
|
zoneid=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone&status=active" \
|
||||||
-H "X-Auth-Email: $cloudflare_auth_email" \
|
-H "X-Auth-Email: $cloudflare_auth_email" \
|
||||||
|
Loading…
Reference in New Issue
Block a user