Skip to content

Instantly share code, notes, and snippets.

@fercreek
Last active September 12, 2018 02:34
Show Gist options
  • Save fercreek/4935441973bf6c33fcd6ba6a54fa3f7e to your computer and use it in GitHub Desktop.
Save fercreek/4935441973bf6c33fcd6ba6a54fa3f7e to your computer and use it in GitHub Desktop.
SimpleBackup.sh
#!/usr/bin/env bash
# input: file or folder
# output: file with .bak ext or folder tar.gz ext
main(){
input=${1}
if [[ -f ${input} ]]; then
# copy file
cp ${input} "${1%.*}-$(date +%s).bak"
# Copying file without extension
echo "It's a file"
elif [[ -d ${input} ]]; then
# Zipping with tar dependency
tar czf "${input}-$(date +%s).tar.gz" ${input}
echo "It's a directory"
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment