diff --git a/scripts/post_end b/scripts/post_end deleted file mode 100755 index 3e8c942..0000000 --- a/scripts/post_end +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -rm -rf "$HOME/.borgmatic/restore" - diff --git a/scripts/post_endmacos b/scripts/post_endmacos deleted file mode 100755 index 7e9d511..0000000 --- a/scripts/post_endmacos +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -rm -rf "$HOME/restore" diff --git a/scripts/post_gitea b/scripts/post_gitea deleted file mode 100755 index fb2857b..0000000 --- a/scripts/post_gitea +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -rm -rf /backups/git/gitea - diff --git a/scripts/post_postgresql b/scripts/post_postgresql deleted file mode 100755 index c10d474..0000000 --- a/scripts/post_postgresql +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -rm -rf /backups/database/postgresql - diff --git a/scripts/postgresql b/scripts/postgresql new file mode 100755 index 0000000..b8fd669 --- /dev/null +++ b/scripts/postgresql @@ -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 diff --git a/scripts/pre_debian b/scripts/pre_debian deleted file mode 100755 index 3b4e86f..0000000 --- a/scripts/pre_debian +++ /dev/null @@ -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 </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 diff --git a/scripts/pre_fedora b/scripts/pre_fedora deleted file mode 100755 index 38280d6..0000000 --- a/scripts/pre_fedora +++ /dev/null @@ -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" < "${giteaDir}/gitea-dump-${backupDate}.tar.xz" diff --git a/scripts/pre_macos b/scripts/pre_macos deleted file mode 100755 index e52e0c5..0000000 --- a/scripts/pre_macos +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -restoreDir="$HOME/.borgmatic/restore" - -mkdir -p "$restoreDir" -pushd "$restoreDir" || exit -brew bundle dump - -cat > "${restoreDir}/restore.sh" < /etc/restore/packages.list diff --git a/scripts/pre_suse b/scripts/pre_suse deleted file mode 100755 index b25abf9..0000000 --- a/scripts/pre_suse +++ /dev/null @@ -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 <" + 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 diff --git a/templates/config.yaml.tpl b/templates/config.yaml.tpl index 31f05d0..4839774 100644 --- a/templates/config.yaml.tpl +++ b/templates/config.yaml.tpl @@ -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.