diff --git a/README.md b/README.md index 88c25c9..7452714 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ ### Bash +**backupProgramFiles.sh** +This is a script that I created to zip up my Program Files folders on my C: drive as those are permanently excluded by the backup software I use. I could probably dive in and pick specific applications that I know store their configutaions in the Program Files folders but for now I just do the whole thing. This script also clears out backups older than 2 weeks (I run it weekly) and emails a summary to the provided address through the specified mail relay server. Be sure to edit smtp-creds.sh to include your information. + **convertHEICtoJPG.sh** This script will convert your HEIC files (a format Apple saves photos with) to JPGs. Flip saveasjpg at the top to save as PNG instead. This will result in much larger file sizes. Set keeporiginals to 0 to delete the HEIC files after they're converted. The HEIC files are saved kept around by default. For best results set this up as a cron job. \* Requires the ImageMagick CLI software to be installed with HEIC support. There are links at the top of the script to do this. diff --git a/bash/backupProgramFiles.sh b/bash/backupProgramFiles.sh new file mode 100755 index 0000000..c1b0354 --- /dev/null +++ b/bash/backupProgramFiles.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +_err=0 +which 7z >/dev/null || let _err="_err+1" +which s-nail >/dev/null || let _err="_err+2" + +if [[ $_err -ge 2 ]]; then echo "Please install s-nail.";fi +if [[ $_err -eq 1 ]] || [[ $_err -eq 3 ]]; then echo "Please install p7zip-full.";fi +[ $_err -ge 1 ] && exit; + + +source /path/to/your/smtp-creds.sh +if [ $? -ne 0 ]; then echo "Please fill in the path to your smtp-creds.sh file.";exit;fi + +if [ $smtp_defaults -eq 1 ]; then echo "Please edit your smtp-creds file.";exit;fi + +backupdate=`date +%Y-%m-%d_%H-%M-%S%z` + +logfile="/mnt/b/Backups/ProgramFiles/ProgramFiles-$backupdate.log" +backupdir="/mnt/b/Backups/ProgramFiles" + +isodate=`date +%Y-%m-%d_%H-%M-%S%z` +echo -e "[$isodate] Backup script starting" >> $logfile + +isodate=`date +%Y-%m-%d_%H-%M-%S%z` +echo -e "[$isodate] Checking for backups older than 7 days..." >> $logfile + +oldbackups=`find $backupdir -type f -mtime +7 -exec ls -lh {} \;` + +isodate=`date +%Y-%m-%d_%H-%M-%S%z` +echo -e "[$isodate] Found the following backups to be deleted:\n" >> $logfile + +echo -e $oldbackups | sed 's/\.7z\ /\.7z\n/g' >> $logfile + +isodate=`date +%Y-%m-%d_%H-%M-%S%z` +echo -e "\n[$isodate] Deleting the above backups..." >> $logfile +echo -e $oldbackups | sed 's/\.7z\ /\.7z\n/g' | rev | cut -d' ' -f1 | rev | grep 1 | xargs rm -f + +isodate=`date +%Y-%m-%d_%H-%M-%S%z` +echo -e "[$isodate] Old backups deleted." >> $logfile + +echo -e "[$isodate] Starting the backup...\n\n" >> $logfile +# Run the backup +7z a $backupdir/ProgramFiles-$backupdate.7z -x\!/mnt/c/Program\ Files/Common\ Files/* /mnt/c/Program\ Files /mnt/c/Program\ Files\ \(x86\) >> $logfile + +isodate=`date +%Y-%m-%d_%H-%M-%S%z` +echo -e "[$isodate] The backup has completed." >> $logfile + +backupsize=`ls -lh $backupdir/ProgramFiles-$backupdate.7z | cut -d' ' -f5` + +echo -e "[$isodate] The backup file's size is $backupsize." >> $logfile + +isodate=`date +%Y-%m-%d_%H-%M-%S%z` +echo -e "\n\n\n[$isodate] Backup script completed, sending email." >> $logfile +cat $logfile | s-nail -s "Weekly Program Files Backup Results" -S smtp-use-starttls -S ssl-verify=ignore -S smtp-auth=login -S smtp=smtp://$smtp_relay:587 -S from="$smtp_from" -S smtp-auth-user=$smtp_user -S smtp-auth-password=$smtp_pass -S ssl-verify=ignore $smtp_to >> $logfile + diff --git a/bash/smtp-creds.sh b/bash/smtp-creds.sh new file mode 100644 index 0000000..862a682 --- /dev/null +++ b/bash/smtp-creds.sh @@ -0,0 +1,7 @@ +#!/bin/bash +smtp_defaults=1 # Set to 0 to allow the script to run +smtp_relay="your SMTP relay server address" +smtp_user="your SMTP relay server username" +smtp_pass="your SMTP relay server password" +smtp_to="where you want the email to go" +smtp_from="what you want to show in the from field"