|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# ---------------------------------- # |
| 4 | +# >>>>> CONFIGURATION SETTINGS <<<<< # |
| 5 | +# ---------------------------------- # |
| 6 | + |
| 7 | +# Backups save location (FULL PATH) |
| 8 | +backup_location="/wynZFS/Wynand/TestBackups" |
| 9 | + |
| 10 | +# Backup folders (RELATIVE TO backup_location) |
| 11 | +acm_save_location="/aconfmgr" |
| 12 | +borg_save_location="/Antergos" |
| 13 | +gmv_save_location="/Gmail" |
| 14 | + |
| 15 | +# Folder(s) to backup (FULL PATH)(Comma seperated list) |
| 16 | +backed_up_files="/home" |
| 17 | + |
| 18 | +# Folder(s) to exclude from backups (Exlude folders based on PATTERN)(Comma seperated list) |
| 19 | +excluded_folders="/home/wynand/Downloads, /home/wynand/wynZFS" |
| 20 | +excluded_patterns="*cache*, *nohup*, *steam*, *Steam*" |
| 21 | + |
| 22 | +#Location of passwords file (FULL PATH) |
| 23 | +password_file_location="/home/wynand/.passwords.asc" ##Need to specify format |
| 24 | + |
| 25 | +# Aconfmgr (FULL PATH)(leave BLANK for default) |
| 26 | +acm_path="" |
| 27 | + |
| 28 | +# Borg (FULL PATH)(leave BLANK for default) |
| 29 | +borg_path="" |
| 30 | + |
| 31 | +# Borg prune options |
| 32 | +borg_keep_hourly="24" |
| 33 | +borg_keep_daily="7" |
| 34 | +borg_keep_weekly="4" |
| 35 | +borg_keep_monthly="12" |
| 36 | +borg_keep_yearly="10" |
| 37 | + |
| 38 | +# Gmail (FULL PATH)(leave BLANK for default) |
| 39 | +gmv_path="/home/wynand/.virtualenv2/gmvault/bin/gmvault" |
| 40 | +email_address="wynandgouwswg@gmail.com" |
| 41 | + |
| 42 | +# --------------------------------- # |
| 43 | +# >>>>>>> END CONFIGURATION <<<<<<< # |
| 44 | +# --------------------------------- # |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +acm_save_location=$backup_location$acm_save_location |
| 49 | +borg_save_location=$backup_location$borg_save_location |
| 50 | +gmv_save_location=$backup_location$gmv_save_location |
| 51 | + |
| 52 | +excluded_folders="--exclude "${excluded_folders//,/\ --exclude} |
| 53 | +excluded_folders=${excluded_folders//\"/ } |
| 54 | +excluded_patterns=${excluded_patterns//\ /} |
| 55 | +excluded_patterns="--exclude "${excluded_patterns//,/\ --exclude } |
| 56 | +backed_up_files=${backed_up_files//,/\ } |
| 57 | +backed_up_files=${backed_up_files//\"/ } |
| 58 | + |
| 59 | +set -a |
| 60 | +source <(gpg -qd $password_file_location) |
| 61 | +set +a |
| 62 | + |
| 63 | +if [ -z $acm_path ] |
| 64 | +then |
| 65 | + acm_path=$(which aconfmgr) |
| 66 | + if [ $acm_path = "aconfmgr not found" ] |
| 67 | + then |
| 68 | + echo "ERROR: aconfmgr not found"; exit 1; |
| 69 | + fi |
| 70 | +fi |
| 71 | + |
| 72 | +if [ -z $borg_path ] |
| 73 | +then |
| 74 | + borg_path=$(which borg) |
| 75 | + if [ $borg_path = "borg not found" ] |
| 76 | + then |
| 77 | + echo "ERROR: borg not found"; exit 1; |
| 78 | + fi |
| 79 | +fi |
| 80 | + |
| 81 | +if [ -z $gmv_path ] |
| 82 | +then |
| 83 | + gmv_path=$(which gmvault) |
| 84 | + if [ $gmv_path = "gmvault not found" ] |
| 85 | + then |
| 86 | + echo "ERROR: gmv not found"; exit 1; |
| 87 | + fi |
| 88 | +fi |
| 89 | + |
| 90 | +notify-send "Backup Started""" |
| 91 | + |
| 92 | +# Backup my crontab |
| 93 | +# crontab -l > /home/wynand/GoogleDrive/01_Personal/05_Software/Antergos/wyntergos_crontab |
| 94 | + |
| 95 | +# Create backups of save locations |
| 96 | +borg init $borg_save_location |
| 97 | +borg create $excluded_folders $excluded_patterns -p -C lz4 $borg_save_location::"{hostname}-{now:%Y%m%d-%H%M}" $backed_up_files |
| 98 | + |
| 99 | +# Backup Gmail using gmvault |
| 100 | +#expect <<- DONE |
| 101 | + #set timeout -1 |
| 102 | + #spawn $gmv_path sync -e -d $gmv_save_location $email_address -p |
| 103 | + #match_max 100000 |
| 104 | + #expect -re {Please enter gmail password for } |
| 105 | + #send "$GOOGLE_PASSPHRASE" |
| 106 | + #send -- "\r" |
| 107 | + #expect eof |
| 108 | +#DONE |
| 109 | + |
| 110 | +# Save packages and configurations using aconfmgr |
| 111 | +#expect <<- DONE |
| 112 | + #set timeout -1 |
| 113 | + #spawn aconfmgr -c $acm_save_location save |
| 114 | + #match_max 100000 |
| 115 | + #expect -re {\[0m\[sudo\] password for } |
| 116 | + #send "$SUDO_PASSPHRASE" |
| 117 | + #send -- "\r" |
| 118 | + #expect eof |
| 119 | +#DONE |
| 120 | + |
| 121 | +# Prune Backups |
| 122 | +echo "Pruning........." |
| 123 | +borg prune $borg_save_location --prefix "{hostname}-" --keep-hourly=$borg_keep_hourly --keep-daily=$borg_keep_daily --keep-weekly=$borg_keep_weekly --keep-monthly=$borg_keep_monthly --keep-yearly=$borg_keep_yearly |
| 124 | + |
| 125 | +# Check backups and alert if issues |
| 126 | +echo "Checking........" |
| 127 | +borg check $borg_save_location &>> $borg_save_location/.tmp.txt |
| 128 | + |
| 129 | +if grep -Fq "Completed repository check, errors found" $borg_save_location/.tmp.txt |
| 130 | +then |
| 131 | + notify-send "Backup Error" "There was an error found in one of the Borg backups" |
| 132 | + mv $borg_save_location/.tmp.txt ~/BorgErrors.txt |
| 133 | +else |
| 134 | + rm -rf $borg_save_location/.tmp.txt |
| 135 | + notify-send "Backups Checked" "All clear" |
| 136 | + # Only copy files to HDD and mega if no errors |
| 137 | + |
| 138 | +echo "Copying........." |
| 139 | + # Copy to External Drive |
| 140 | +# cp -Lruv /home/wynand/wynZFS/Wynand/Backups /run/media/wynand/Wyntergos_Backups |
| 141 | + |
| 142 | + #Upload to mega.nz |
| 143 | +# echo "Uploading......." |
| 144 | +# nocorrect megacopy -u ${mega_user} -p ${mega_password} -r /Root/Backups -l /wynZFS/Wynand/Backups |
| 145 | +# megasync |
| 146 | +fi |
| 147 | + |
| 148 | +# kill $(pgrep megasync) |
| 149 | + |
| 150 | +# to clear imported variables when script quits, to attempt to prevent passwords being taken |
| 151 | +exec bash |
0 commit comments