From 553d15e38bcfb14d0fffe7f6d338f4bd2a777b1f Mon Sep 17 00:00:00 2001 From: fabian Date: Sun, 17 Mar 2024 17:58:00 +0100 Subject: [PATCH] updated/ generalised backup scripts --- scripts/backup_edi.sh | 31 +++++-------------------------- scripts/backup_garrus.sh | 13 +++++++------ scripts/backup_resources.sh | 30 ++++++++++++++++++++++++++++++ scripts/backup_shepard.sh | 15 +++++++++------ 4 files changed, 51 insertions(+), 38 deletions(-) create mode 100644 scripts/backup_resources.sh diff --git a/scripts/backup_edi.sh b/scripts/backup_edi.sh index 9d422e0..adee0e9 100755 --- a/scripts/backup_edi.sh +++ b/scripts/backup_edi.sh @@ -1,34 +1,10 @@ #!/usr/bin/env bash set -euo pipefail -source /sync/home_external/.bash_aliases +source /sync/scripts/backup_resources.sh +# FSFIXME expand_aliases still needed? shopt -s expand_aliases # make aliases work - -backupRootDirectory() { - ensureRootDirectory $2 - sd rsync_backup $1 $2 -} - - -backupDirectory() { - ensureDirectory $2 - rsync_backup $1 $2 -} - - -ensureRootDirectory() { - ensureDirectory $1 - sudo chown root:root $1 -} - - -ensureDirectory() { - if [[ ! -e $1 ]]; then - mkdir -p $1 - fi -} - ############################### ### update local backup dir ### ############################### @@ -37,10 +13,12 @@ BACKUP_DIR=/sync/backup ensureDirectory $BACKUP_DIR BACKUP_DIR_HOME=$BACKUP_DIR/home ensureDirectory $BACKUP_DIR_HOME + backupDirectory $HOME/.ssh/ $BACKUP_DIR_HOME/.ssh/ BACKUP_DIR_ROOT=$BACKUP_DIR/root/etc ensureRootDirectory $BACKUP_DIR_ROOT + sd rsync_backup /etc/hosts $BACKUP_DIR_ROOT/ sd rsync_backup /etc/ddclient.conf $BACKUP_DIR_ROOT/ backupRootDirectory /etc/ddclient/ $BACKUP_DIR_ROOT/ddclient/ @@ -60,3 +38,4 @@ fi sd rsync_backup -e "ssh -i /home/edi/.ssh/id_ed25519" --filter="P /home/docker" /sync/backup/ fabian@garrus:/citadel/backup/edi/ sd rsync_backup -e "ssh -i /home/edi/.ssh/id_ed25519" /home/edi/docker/ fabian@garrus:/citadel/backup/edi/home/docker/ +echo "Note: remember to keep /citadel in sync!" diff --git a/scripts/backup_garrus.sh b/scripts/backup_garrus.sh index c8e24bb..bea10dc 100755 --- a/scripts/backup_garrus.sh +++ b/scripts/backup_garrus.sh @@ -1,22 +1,22 @@ #!/usr/bin/env bash set -euo pipefail -source /sync/home_external/.bash_aliases +source /sync/scripts/backup_resources.sh +# FSFIXME expand_aliases still needed? shopt -s expand_aliases # make aliases work - ############################### ### update local backup dir ### ############################### BACKUP_DIR=/sync/backup +ensureDirectory $BACKUP_DIR BACKUP_DIR_HOME=$BACKUP_DIR/home -if [[ !($HOME/.bash_aliases_local -ef $BACKUP_DIR_HOME/.bash_aliases_local) ]]; then - ln $HOME/.bash_aliases_local $BACKUP_DIR_HOME/.bash_aliases_local -fi +ensureDirectory $BACKUP_DIR_HOME BACKUP_DIR_ROOT=$BACKUP_DIR/root/etc -rsync_backup --link-dest="/etc/ssh/" /etc/ssh/ $BACKUP_DIR_ROOT/ssh/ +ensureRootDirectory $BACKUP_DIR_ROOT +backupRootDirectory /etc/ssh/ $BACKUP_DIR_ROOT/ssh/ if [[ !(-d $BACKUP_DIR_ROOT/udev/rules.d) ]]; then mkdir $BACKUP_DIR_ROOT/udev/rules.d fi @@ -24,6 +24,7 @@ if [[ !(/etc/udev/rules.d/69-hdparm.rules -ef $BACKUP_DIR_ROOT/udev/rules.d/69-h ln /etc/udev/rules.d/69-hdparm.rules $BACKUP_DIR_ROOT/udev/rules.d/69-hdparm.rules fi +backupRootDirectory /etc/ssh/ $BACKUP_DIR_ROOT/ssh/ ##################### ### upload backup ### diff --git a/scripts/backup_resources.sh b/scripts/backup_resources.sh new file mode 100644 index 0000000..c99b601 --- /dev/null +++ b/scripts/backup_resources.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -euo pipefail + +source /sync/home_external/.bash_aliases +shopt -s expand_aliases # make aliases work + + +backupRootDirectory() { + ensureRootDirectory $2 + sd rsync_backup $1 $2 +} + + +backupDirectory() { + ensureDirectory $2 + rsync_backup $1 $2 +} + + +ensureRootDirectory() { + ensureDirectory $1 + sudo chown root:root $1 +} + + +ensureDirectory() { + if [[ ! -d $1 ]]; then + mkdir -p $1 + fi +} diff --git a/scripts/backup_shepard.sh b/scripts/backup_shepard.sh index 84d9b1f..f14eb87 100755 --- a/scripts/backup_shepard.sh +++ b/scripts/backup_shepard.sh @@ -1,24 +1,27 @@ #!/usr/bin/env bash set -euo pipefail -source /sync/home_external/.bash_aliases +source /sync/scripts/backup_resources.sh +# FSFIXME expand_aliases still needed? shopt -s expand_aliases # make aliases work - ############################### ### update local backup dir ### ############################### BACKUP_DIR=/sync/backup +ensureDirectory $BACKUP_DIR BACKUP_DIR_HOME=$BACKUP_DIR/home -if [[ !($HOME/.bash_aliases_local -ef $BACKUP_DIR_HOME/.bash_aliases_local) ]]; then - ln $HOME/.bash_aliases_local $BACKUP_DIR_HOME/.bash_aliases_local -fi -rsync_backup --link-dest="$HOME/.ssh/" $HOME/.ssh/ $BACKUP_DIR_HOME/.ssh/ +ensureDirectory $BACKUP_DIR_HOME +backupDirectory $HOME/.ssh/ $BACKUP_DIR_HOME/.ssh/ ##################### ### upload backup ### ##################### +if [[ "$1" == "--noupload" ]]; then + exit 0; +fi + sd rsync_backup -e "ssh -i /home/fabian/.ssh/id_ed25519" $BACKUP_DIR/ fabian@garrus:/citadel/backup/shepard/