Last active
November 13, 2021 18:56
-
-
Save YoussefLagtab/031284fbb9c5063b66db4916bf5d7b45 to your computer and use it in GitHub Desktop.
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 | |
# Usage !! | |
# + rclone | |
# - install rclone from https://rclone.org/install/ | |
# - setup a remote with `rclone config` | |
# - change the next line with your remote and a direcory name you want in that remote (remote:dir) | |
RCLONE_REMOTE_DI='1337:iMac_backup' | |
# + files to backup | |
# - create a file containing the files and directories you want to back up one entry per line | |
# - change the next line with the path of your file that you just created | |
FILES_TO_BACKUP=~/.local/etc/iMac_backup/files_to_backup | |
# + backup directory | |
# change the next line with your local backup direcoty of choice | |
BACKUP_DIRECTORY='/goinfre/ylagtab/backup' | |
# variables | |
H=~ | |
BACKUP_DIRECTORY_SAVE=$BACKUP_DIRECTORY'.save' | |
LOGS_DIR=$H'/.local/var/iMac_backup' | |
LOG_FILE='backup.log' | |
PROGRESS_FILE='rclone.progress' | |
# setup printing | |
mkdir -p $LOGS_DIR; | |
exec &> $LOGS_DIR/$LOG_FILE; | |
# copy files to backup direcroty | |
function copy_files_to_backup_directory() | |
{ | |
echo + Start copying:; | |
for filename in `cat $FILES_TO_BACKUP`; do | |
filepath=~/$filename; | |
[ -a $filepath ] || continue ; | |
echo \ - copying $filepath; | |
if [ -d $filepath ]; | |
then | |
cp -R $filepath $BACKUP_DIRECTORY/`echo $filename | tr / _`; | |
else | |
cp $filepath $BACKUP_DIRECTORY; | |
fi; | |
done; | |
echo + Finished copying; | |
} | |
# uploading backup to drive | |
function upload_to_rclone_remote_directory() | |
{ | |
echo \+ + Start Upload:; | |
rclone copy $BACKUP_DIRECTORY 1337:iMac_backup -L --progress --bwlimit 8M 1> $LOGS_DIR/$PROGRESS_FILE; | |
echo \+ + Finished Upload:; | |
} | |
# setup directories | |
function setup_directories() | |
{ | |
echo + setup directories; | |
rm -fr $BACKUP_DIRECTORY_SAVE; | |
[ -a $BACKUP_DIRECTORY ] && mv $BACKUP_DIRECTORY $BACKUP_DIRECTORY_SAVE; | |
mkdir $BACKUP_DIRECTORY; | |
# attach a date to backup directory | |
echo \[ `date +"%d-%m-%Y %H:%M:%S"` \] > $BACKUP_DIRECTORY/.date; | |
} | |
function main() | |
{ | |
setup_directories; | |
# print date | |
echo "===================================================================="; | |
echo \[ `date +"%d-%m-%Y %H:%M:%S"` \]\:; | |
echo "===================================================================="; | |
copy_files_to_backup_directory; | |
upload_to_rclone_remote_directory; | |
echo + done; | |
} | |
main & | |
disown; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment