Last active
December 28, 2019 03:01
-
-
Save Scarsz/a0fbeb83e7ae7d00328c153656fd0e12 to your computer and use it in GitHub Desktop.
crontab-able nightly backup to mega.nz via megatools
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 | |
locationstocompress=( "/home" "/var/www" ) | |
identifier="WEB-1" | |
megaemail="email@provider.com" | |
megapass="password" | |
# Edit below this if you're feeling lucky | |
masterfile="$identifier-$(date +"%Y-%m-%d").tar.gz" | |
masterfileweekago="$identifier-$(date +"%Y-%m-%d" --date="7 days ago").tar.gz" | |
tmpdir="/tmp/backup-$(echo $RANDOM % 999999 + 1 | bc)" | |
masterfile="/tmp/$masterfile" | |
echo "Turning off swap" | |
swapoff -a | |
mkdir "$tmpdir" | |
echo "Compressing to $masterfile" | |
for location in "${locationstocompress[@]}"; do | |
echo "Compressing $location" | |
locationfile="$tmpdir/$(echo "$location" | tr / - | cut -c 2-).tar.gz" | |
tar -cI pigz -f "$locationfile" "$location" | |
done | |
echo "Compressing master file" | |
tar -cI pigz -f "$masterfile" -C "$tmpdir" . | |
rm -r "$tmpdir" | |
echo "Uploading to mega.nz" | |
megaput -u "$megaemail" -p "$megapass" "$masterfile" | |
echo "Deleting master file" | |
rm "$masterfile" | |
echo "Deleting week old backup" | |
megarm --reload -u "$megaemail" -p "$megapass" "/Root/$masterfileweekago" | |
echo "Turning on swap" | |
swapon -a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment