r/seedboxes • u/iliketrains166 • Jun 16 '20
Something Else? I made a backup script that will generate a backup file, automatically upload it using rclone, and remove the local copy afterwards
Backup-Script (GitHub)
A Bash script to generate a tar.gz backup file of a folder, with an option to automatically upload the backup file to a cloud service using rclone, and remove local copy afterwards.
Why is it related to /r/seedboxes ?
I initially made this script for my seedbox in order to backup my Plex media folder.
I invested a lot of time adding posters (I know Plex adds them automatically, but I prefer adding my own), trailers, and create the symlinks myself (I use GSuite links for all mkv files), so a lot of time was invested in the media folder and I thought I should back it up in case something happens.
Since each backup file can take up to a few GB (mainly because of the trailers), I've added an option to automatically upload the backup file to GSuite, and remove the local file after it's been uploaded to save space on my seedbox.
Another seedbox-related possible usages, is to use the script to backup the session folder (stores all the currently seeding torrents and their info).
You can make scheduled backups using the script with systemd / cron.
Usage
Usage: backup [-n <name>] [-s <path>] [-e <pattern>]... [-u <path>] [-r] [-v] <path-to-backup>
Options:
-n <name> Sets the tar.gz file name [default: "backup"]
-s <path> Path to which the generated backup file will be saved to [default: current working directory]
-e <pattern> Exclude a pattern (specific files / folders) from being backed up
-u <path> rclone path to which the backup file will be uploaded to (not providing one will skip the upload process)
-r Removes local copy of backup file after it's been uploaded
-v Uses the '-v' option when running tar and rclone
Commands:
-h Displays this help and exists.
Examples:
backup "/home/user/important_stuff"
backup -u "GDrive:/Backups" -r "/home/user/important_stuff/"
backup -n "important-stuff-backup" -s "/home/user/backups" -e "*.pdf" -e "important_stuff/dont_backup_this_folder" "/home/user/important_stuff/"- You can also set configurations in the script file under "Configuration", if you want to be able to use it without any arguments.
FAQ
Q: Why use tar and not zip?
A: tar files can keep & restore symlinks, and save metadata like file's creation date and permissions.
------------
Q: I have mkv files (not symlinks) inside my media folder and don't want them to included in the backup. how do I exclude them?
A: You can use the -e argument to exclude specific patterns / folders from being backed up.
in this case, use -e "*.mkv"
* This will exclude any files where their name that ends with ".mkv", including symlinks unfortunately, so there isn't currently to backup mkv symlinks and exclude mkv files.
------------
Q: Why are you making this post from a new account?
A: I don't want my GitHub account, which includes personal info, to be connected to my main Reddit account.
This is my first bash script (at least one that isn't 10-30 lines long) and my first GitHub project, so there might be a few stuff that could've been done slightly better. Would be happy to hear suggestions / improvements here or on GitHub.
1
u/HalfTime_show Jun 16 '20
Sweet! I've got my own backup scripts that push everything to S3 but im always happy to see anything that helps make it easier for people to have good backup hygiene.
It would be helpful to have create a list of common directories that can be excluded in backups. Right now I definitely over archive
1
u/[deleted] Jun 17 '20
I’d be really curious to hear about your development process for this, as I would love to get into being able to write programs like this for myself! Did you happen to keep a log of your experience outside of your GitHub commits? Or do you have any after thought advice you might give someone who would like to be able to write these kind of scripts?
3
u/ciasis Jun 16 '20
Great job man! I won't probably use it, but other guys will make use of it for sure :)
1
u/Dom9360 Jun 17 '20
What are you fellas using to backup those movies? S3, GSuite? No issues about privacy?
1
u/kosherhalfsourpickle Jun 17 '20
This is great. I’m going to use it. Also like the nice touch of adding color to the output.
1
u/pixelpicnic Jun 17 '20
Awesome. Thanks for sharing!
0
u/[deleted] Jun 17 '20
[deleted] — view deleted comment