Last active
September 24, 2017 12:11
-
-
Save hr-sadooghi/4975288c81512b2acae308b6137da9c7 to your computer and use it in GitHub Desktop.
This bash script create backup from specified dir or files with current Jalali datetime postfix.
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/bash | |
# This file depend on jdate command | |
# You can build jdate from source with this guide: https://wiki.ubuntu.ir/wiki/Jcal | |
if [$1 = ] | |
then | |
echo "no files given" | |
exit 0 | |
fi | |
echo -ne "Number of files to backup: $#\r\n\r\n" | |
for file in $*; do | |
# stat $file > /dev/null 2>&1 | |
# $? -eq 0 | |
if [ -e $file ] | |
then | |
backup_file="${file}_`jdate +%Y-%m-%d-%H-%M`.bak" | |
if [ -d $file ]; then | |
cp -r $file $backup_file > /dev/null 2>&1 | |
else | |
cp $file $backup_file > /dev/null 2>&1 | |
fi | |
if [ $? -eq 0 ] | |
then | |
echo -ne "Backup\t\e[32mDone\e[0m \t\tfor \t\e[43m$file\e[0m ==> \e[43m$backup_file\e[0m" | |
else | |
echo -ne "Backup\t\e[31mFail\e[0m \tfor \t\e[43m$file\e[0m ==> \e[43m$backup_file\e[0m" | |
fi | |
else | |
echo -ne "File\t\e[31mNot Exist!\e[0m \tfor \t\e[43m$file\e[0m" | |
fi | |
echo -ne "\r\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment