Skip to content

Instantly share code, notes, and snippets.

@StrikeW
Created October 13, 2014 03:11
Show Gist options
  • Save StrikeW/59f0a6909aef44f63a1d to your computer and use it in GitHub Desktop.
Save StrikeW/59f0a6909aef44f63a1d to your computer and use it in GitHub Desktop.
Tiny script used to backup folders
#!/bin/bash
#
# backup - Tiny script used to backup folders. This
# is an exercise for learning shell programming.
#
#
# Join elements in array
#
function join() {
local IFS="$1";
shift;
echo "$*";
}
source=('/Users/siyuan/notes' '/Users/siyuan/books')
target_dir='/Users/siyuan/backup'
target=$target_dir/$(date +"%Y%m%d%H%M%S").zip
# Craete target directory if it is not present
if ! [[ -e $target_dir ]]; then
mkdir $target_dir
fi
sources=$(join ' ' "${source[@]}")
zip_command="zip -r $target $sources"
echo Zip command is:
echo $zip_command
echo Running:
$zip_command
if [[ $? = 0 ]]; then
echo "Successful backup to $target"
else
echo "Backup FAILED"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment