Skip to content

Instantly share code, notes, and snippets.

@svandragt
Last active January 6, 2017 16:13
Show Gist options
  • Save svandragt/8aa871b1bc8d2a1cf25f9c5c1020e1ba to your computer and use it in GitHub Desktop.
Save svandragt/8aa871b1bc8d2a1cf25f9c5c1020e1ba to your computer and use it in GitHub Desktop.
Linux Server Configuration and Setup History Repository
# binit - new backup repository
# bcom <filename> - backup file to git repo keeping path
# bex <command> - execute command and log the command to history
#
# Add this to .bashrc then use the above commands. Still does not work as well as ansible I presume.
backup_commit() {
# backup file if argument is provided
if [ "$#" -gt 0 ]
then
dst_path=$HOME/backup`realpath $1`
mkdir -p `dirname $dst_path`
cp $1 $dst_path
fi
# always commit
pushd $HOME/backup >/dev/null
git add *
if [ "$#" -gt 1 ]
then
git commit -m "${@:2}"
else
git commit
fi
popd >/dev/null
}
alias bcom=backup_commit
backup_init() {
# backup using git repo
mkdir $HOME/backup
pushd $HOME/backup
git init
popd
}
alias binit=backup_init
backup_execute() {
echo "$*" | tee --append $HOME/backup/history.log
$*
}
alias bex=backup_execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment