Last active
March 31, 2016 17:33
-
-
Save yusufb/b53fd6ae5847ad87c6327a002b07dccd to your computer and use it in GitHub Desktop.
backup files before diving into code
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/sh | |
if [ $# -eq 0 ]; then | |
echo "filename(s) to backup is missing. exiting." | |
exit 1 | |
fi | |
BACKUP_DATE=`date +%Y-%m-%d_%H:%M:%S` | |
BACKUP_EXT_PREFIX="backup" | |
for file in "$@" | |
do | |
if [ ! -f $file ]; then | |
echo "\"$file\" does not exist. skipping." | |
continue | |
fi | |
NEW_FILENAME="$file.$BACKUP_EXT_PREFIX.$BACKUP_DATE" | |
cp $file $NEW_FILENAME | |
echo "\"$file\" has been backed up." | |
FILES_TO_LIST="$FILES_TO_LIST $file* " | |
done | |
if [ ${#FILES_TO_LIST} -lt 1 ]; then | |
echo "no files have been backed up." | |
else | |
ls -a $FILES_TO_LIST | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment