Created
October 13, 2014 03:11
-
-
Save StrikeW/59f0a6909aef44f63a1d to your computer and use it in GitHub Desktop.
Tiny script used to backup folders
This file contains hidden or 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 | |
# | |
# 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