Re-created agents and changed template to not use run-parts
This commit is contained in:
parent
d639b50362
commit
e355d55402
14 changed files with 136 additions and 115 deletions
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf "$HOME/.borgmatic/restore"
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf "$HOME/restore"
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf /backups/git/gitea
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf /backups/database/postgresql
|
||||
|
31
scripts/postgresql
Executable file
31
scripts/postgresql
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
restoreDir=/etc/restore
|
||||
pgsqlDir="$restoreDir/postgresql"
|
||||
|
||||
hook_check() {
|
||||
if [[ -d "$pgsqlDir" ]]; then
|
||||
rm -rf "$pgsqlDir" || exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
hook_pre() {
|
||||
state=$(nc 127.0.0.1 5400)
|
||||
|
||||
if [[ "$state" != "MASTER" ]]; then
|
||||
#backupDate=$(date +"%Y-%m-%d")
|
||||
|
||||
mkdir -p "$pgsqlDir" || exit 2
|
||||
/usr/local/sbin/pg_backup -c /etc/postgresql/9.6/main/pg_backup.config
|
||||
fi
|
||||
}
|
||||
|
||||
hook_post() {
|
||||
rm -rf "$pgsqlDir" || exit 1
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
before_check) hook_check;;
|
||||
before_backup) hook_pre;;
|
||||
after_backup) hook_post;;
|
||||
esac
|
|
@ -1,34 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ -d /etc/restore ]]; then
|
||||
rm -rf /etc/restore
|
||||
fi
|
||||
|
||||
mkdir /etc/restore
|
||||
dpkg --get-selections > /etc/restore/Package.list
|
||||
aptitude search --disable-columns -F%p '~i!~M!~v' > /etc/restore/InstallOnly.list
|
||||
#apt-key exportall > /etc/restore/Repo.keys
|
||||
rsync -avhHi /etc/apt/trusted.gpg.d /etc/restore/
|
||||
|
||||
cat > /etc/restore/restore.sh <<EOF
|
||||
#!/bin/bash
|
||||
|
||||
#apt-key add /etc/restore/Repo.keys
|
||||
#dpkg --set-selections < /etc/restore/Package.list
|
||||
#apt-get dselect-upgrade
|
||||
|
||||
install=""
|
||||
|
||||
dpkg-query -l 'rsync' &>/dev/null || install+=" rsync"
|
||||
dpkg-query -l 'aptitude' &>/dev/null || install+=" aptitude"
|
||||
dpkg-query -l 'borgbackup' &>/dev/null || install+=" borgbackup"
|
||||
dpkg-query -l 'borgmatic' &>/dev/null || install+=" borgmatic"
|
||||
|
||||
if [[ -n "\$install" ]]; then
|
||||
apt -y install \$install
|
||||
fi
|
||||
|
||||
rsync --ignore-existing -raz /etc/restore/trusted.gpg.d/ /etc/apt/trusted.gpg.d/
|
||||
xargs aptitude --schedule-only install < /etc/restore/InstallOnly.list
|
||||
aptitude install
|
||||
EOF
|
|
@ -1,12 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
restoreDir="$HOME/.borgmatic/restore"
|
||||
mkdir -p "$restoreDir"
|
||||
rpm -qa | sort > "${restoreDir}/Package.versions.list"
|
||||
rpm -qa --queryformat '%{NAME}.%{ARCH}\n' | sort > "${restoreDir}/etc/restore/Package.list"
|
||||
|
||||
cat > "${restoreDir}/restore.sh" <<EOF
|
||||
#!/bin/bash
|
||||
|
||||
dnf install \$(cat \"\${HOME}/.borgmatic/restore/Package.list\")
|
||||
EOF
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
giteaDir="${HOME}/.borgmatic/gitea"
|
||||
backupDate=$(date +"%Y-%m-%d")
|
||||
|
||||
mkdir -p "$giteaDir"
|
||||
sudo -u git /home/gitea/bin/gitea dump --type tar.xz --file - > "${giteaDir}/gitea-dump-${backupDate}.tar.xz"
|
|
@ -1,22 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
restoreDir="$HOME/.borgmatic/restore"
|
||||
|
||||
mkdir -p "$restoreDir"
|
||||
pushd "$restoreDir" || exit
|
||||
brew bundle dump
|
||||
|
||||
cat > "${restoreDir}/restore.sh" <<EOF
|
||||
#!/bin/bash
|
||||
|
||||
if which brew; then
|
||||
echo "Installing Homebrew Bundle"
|
||||
brew bundle
|
||||
else
|
||||
echo "Install Homebrew first using the following:"
|
||||
echo '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)'
|
||||
echo "Re-run restore.sh after installing Homebrew to install Homebrew Bundle"
|
||||
fi
|
||||
EOF
|
||||
|
||||
popd || exit
|
|
@ -1,8 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
state=$(nc 127.0.0.1 5400)
|
||||
|
||||
if [[ "$state" != "MASTER" ]]; then
|
||||
/usr/local/sbin/pg_backup -c /etc/postgresql/9.6/main/pg_backup.config
|
||||
fi
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
mkdir /etc/restore
|
||||
eopkg li > /etc/restore/packages.list
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
mkdir /etc/restore
|
||||
rpm -qa | sort > /etc/restore/Package.versions.list
|
||||
rpm -qa --queryformat '%{NAME}\n' | sort > /etc/restore/Package.list
|
||||
|
||||
cat > /etc/restore/restore.sh <<EOF
|
||||
#!/bin/bash
|
||||
|
||||
cat /etc/restore/Package.list | xargs sudo zypper install
|
||||
EOF
|
101
scripts/run-parts
Executable file
101
scripts/run-parts
Executable file
|
@ -0,0 +1,101 @@
|
|||
#!/bin/bash
|
||||
# run-parts - concept taken from Debian
|
||||
|
||||
# keep going when something fails
|
||||
set +e
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: run-parts [--args | --list | --test] <dir>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while [ $# -gt 1 ]; do
|
||||
case $1 in
|
||||
--args)
|
||||
runargs=$2
|
||||
shift 2
|
||||
break
|
||||
;;
|
||||
--list)
|
||||
list=1
|
||||
shift
|
||||
break
|
||||
;;
|
||||
--test)
|
||||
test=1
|
||||
shift
|
||||
break
|
||||
;;
|
||||
--)
|
||||
# -- end of options
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
# directory
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -d $1 ]; then
|
||||
echo "Not a directory: $1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f /etc/sysconfig/run-parts ]; then
|
||||
. /etc/sysconfig/run-parts
|
||||
fi
|
||||
|
||||
# Ignore *~ and *, scripts
|
||||
for i in $(LC_ALL=C; echo ${1%/}/*[^~,]) ; do
|
||||
[ -d $i ] && continue
|
||||
# Don't run *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} scripts
|
||||
[ "${i%.cfsaved}" != "${i}" ] && continue
|
||||
[ "${i%.rpmsave}" != "${i}" ] && continue
|
||||
[ "${i%.rpmorig}" != "${i}" ] && continue
|
||||
[ "${i%.rpmnew}" != "${i}" ] && continue
|
||||
[ "${i%.swp}" != "${i}" ] && continue
|
||||
[ "${i%,v}" != "${i}" ] && continue
|
||||
|
||||
# jobs.deny prevents specific files from being executed
|
||||
# jobs.allow prohibits all non-named jobs from being run.
|
||||
# can be used in conjunction but there's no reason to do so.
|
||||
if [ -r $1/jobs.deny ]; then
|
||||
grep -q "^$(basename $i)$" $1/jobs.deny && continue
|
||||
fi
|
||||
if [ -r $1/jobs.allow ]; then
|
||||
grep -q "^$(basename $i)$" $1/jobs.allow || continue
|
||||
fi
|
||||
|
||||
if [ -e $i ]; then
|
||||
if [ -r $1/whitelist ]; then
|
||||
grep -q "^$(basename $i)$" $1/whitelist && continue
|
||||
fi
|
||||
|
||||
if [ ${list:-0} = 1 ]; then
|
||||
echo $i;
|
||||
elif [ -x $i ]; then
|
||||
if [ ${test:-0} = 1 ]; then
|
||||
echo $i;
|
||||
continue
|
||||
fi
|
||||
if [ "$RANDOMIZE" != "" ]; then
|
||||
let "rtime = $RANDOM"
|
||||
if [ "$RANDOMTIME" != "" ]; then
|
||||
let "rtime %= $RANDOMTIME"
|
||||
else
|
||||
let "rtime %= 300"
|
||||
fi
|
||||
sleep $rtime
|
||||
fi
|
||||
|
||||
# run executable files
|
||||
echo "run-parts[$$]" "($1) starting $(basename $i)"
|
||||
$i $runargs 2>&1
|
||||
echo "run-parts[$$]" "($1) finished $(basename $i)"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
|
@ -336,7 +336,7 @@ hooks:
|
|||
# before_backup:
|
||||
# - echo "Starting a backup."
|
||||
before_backup:
|
||||
- run-parts -a before_backup /etc/borgmatic/prebackup.d
|
||||
- /etc/borgmatic/scripts/os before_backup
|
||||
|
||||
# List of one or more shell commands or scripts to execute
|
||||
# before pruning, run once per configuration file.
|
||||
|
@ -347,6 +347,8 @@ hooks:
|
|||
# before consistency checks, run once per configuration file.
|
||||
# before_check:
|
||||
# - echo "Starting checks."
|
||||
before_check:
|
||||
- /etc/borgmatic/scripts/os before_check
|
||||
|
||||
# List of one or more shell commands or scripts to execute
|
||||
# before extracting a backup, run once per configuration file.
|
||||
|
@ -358,7 +360,7 @@ hooks:
|
|||
# after_backup:
|
||||
# - echo "Finished a backup."
|
||||
after_backup:
|
||||
- run-parts -a after_backup /etc/borgmatic/postbackup.d
|
||||
- /etc/borgmatic/scripts/os after_backup
|
||||
|
||||
# List of one or more shell commands or scripts to execute
|
||||
# after pruning, run once per configuration file.
|
||||
|
|
Loading…
Reference in a new issue