Created
August 18, 2021 23:08
-
-
Save joshlong/896cc70ba9d7ee07aaef1fc3971d1f8b to your computer and use it in GitHub Desktop.
backup.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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