Skip to content

Instantly share code, notes, and snippets.

@joshlong
Created August 18, 2021 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshlong/896cc70ba9d7ee07aaef1fc3971d1f8b to your computer and use it in GitHub Desktop.
Save joshlong/896cc70ba9d7ee07aaef1fc3971d1f8b to your computer and use it in GitHub Desktop.
backup.sh
#!/bin/bash
START_DIR=`pwd`
export OS=$( uname | tr '[:upper:]' '[:lower:]' )
export SCRIPT_DIR=$HOME/my-env
export SCRIPT_DIR_BIN=$SCRIPT_DIR/bin
export SCRIPT_OS_DIR=${SCRIPT_DIR}/${OS}
export APP_INSTALL_LOGS=${SCRIPT_OS_DIR}/logs
log=${SCRIPT_DIR}/log.log
cd $SCRIPT_DIR
echo "starting the program in $SCRIPT_DIR" >> $log
rm -rf "$log"
mkdir -p ${HOME}/bin
mkdir -p ${SCRIPT_OS_DIR}
mkdir -p ${APP_INSTALL_LOGS}
RUNTIME=`date`
function sync(){
git pull >> $log
logs_dir=$1
cd $logs_dir
commit_msg="installed application manifests for $OS @ ${RUNTIME}"
last_commit_status=1
find $logs_dir -iname "*.txt" | while read l ; do
result="$(git diff $l)"
if [ "$result" == "" ] ; then
echo "no changes detected for $l"
else
git add $l
git commit $l -m "$commit_msg "
last_commit_status=$?
echo "commiting $l"
fi
done
if [ $last_commit_status -eq 0 ]; then
echo "changes detected on $n. running git push.";
git push;
fi
}
cd $SCRIPT_DIR
echo "Running backup.sh @ ${RUNTIME}. The logs are in ${APP_INSTALL_LOGS} " >> $log
${SCRIPT_DIR}/environment.sh
cd $SCRIPT_DIR
${SCRIPT_OS_DIR}/run.sh
cd $SCRIPT_DIR
sync $APP_INSTALL_LOGS >> $log
cd $START_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment