diff --git a/ConfigBackup b/ConfigBackup new file mode 100755 index 0000000..fcd78d0 --- /dev/null +++ b/ConfigBackup @@ -0,0 +1,47 @@ +#!/bin/bash +#Script to backup all important environment files +source /etc/environment +source $SCRIPTS/Okiru +logging "ConfigBackup" +export CONF_DIR="/home/shmick/Config" +if [[ ! -d $CONF_DIR ]]; then + debug "Cloning Configuration directory in $CONF_DIR" + if git clone ssh://git@git.pukeko.xyz:64278/shmick/Configuration $CONF_DIR; then + ok "Repository cloned succesfully!" + else + error "Error cloning configuration repository!" + exit 1 + fi +else + debug "$CONF_DIR exists; moving on" +fi +##Conf_sync function - if a file exists on filesystem, update in configuration dir; +#+Otherwise, restore it from configuration dir. +conf_sync () { +if [[ -f "$1" ]]; then + info "Copying $1 to configuration directory $CONF_DIR" + rsync -aHAXSvczu "$1" "$CONF_DIR" + cd $CONF_DIR + if [[ -n $(git diff origin/master $(basename $1)) ]]; then + info "Updating changes in file $1" + git commit -am "Auto updating $1 - $(date)" + git push + else + debug "No changes detected in $1" + fi +elif [[ ! -f "$1" ]]; then + warn "$1 does not exist - restoring from configuration directory $CONF_DIR" + rsync -aHAXSvcz "$CONF_DIR/$(basename $1)" "$1" +fi +} +#Configuration files to sync +conf_sync /etc/ddclient.conf $CONF_DIR +for tab in $(ls /var/spool/cron/tabs/*); do + conf_sync $tab +done +conf_sync /etc/environment +conf_sync /etc/hosts +conf_sync /etc/postfix/main.cf + +#Fix permissions +chown -R shmick $CONF_DIR