Multi-purpose Backup script dedicated for Home Servers
❗ Work-in-progress 🔨
Script under developement, designed for homelab application.
Feel free to test, modify, report bugs & propose features.
Have fun 🚀
- Separate
parameters.sh
file for settings & sensitive data - Core functionalities:
- Multiple directory local backup:
- Docker Volumes | With stopping containers
- Docker Bind Mounts | With /or without stopping containers
- Server Home Directory | Separated by sub-directiories
- Cloud backup using
rclone
- Delete old backup files (both locally & in the Cloud)
- Archive locally backup every 10 days
- Multiple directory local backup:
- Additional functionalities:
- Gotify notifications
- Netdata notifications silencer during backup
- Separate 'instant' type to test choosen features
- Linux environment (to execute bash script)
- For required dependencies for each feature see How to use it
File | Description |
---|---|
homeServerBackup.sh |
core of the application |
parameters-sample.sh |
external file with settings & sensitive data |
.gitignore |
git configuration file |
.shellcheckrc |
[ShellCheck][shellCheck] configuration file |
README.md |
documentation file |
LICENSE.md |
open source license details |
- Clone GitHub repository to you server
- Make core script executable
$ chmod u+x homeServerBackup.sh
- Configurate parameters
(!) Before changing any settings / parameters copyparameters-sample.sh
file and remove-sample
part of the name.Complete configuration of script acc. Configuration$ cp parameters-sample.sh parameters.sh
- Execute script
$ sudo ./homeServerBackup.sh -t <TYPE (instant/daily)>
`instant` => used for executing script from terminal `daily` => used in 'sudo crontab' for scheduled backups
- For scheduled backups add above line as cronjob (preferebly with 'daily' type)
- Open crontab
$ sudo crontab -e
- Add scheduled script execution
For example below code with execute script located in everyday at 2:00 am.To set up cron schedule expressions see crontab gutu* 2 * * * cd /<example directory> && ./homeServerBackup.sh -t daily
- Open crontab
- 00. Functionality
- 01. Directories & folders
- 02. Arrays of Docker Containers
- 03. List od Docker Containers with Bind Mounts
- 04. Gotify Configurations
- 05. Netdata silencer
Comment out (with <#>) features to exclude them from executingin 'instant' backups
declare -x -a functionalityInstant=(
'Local Backup | Home directory'
'Local Backup | Docker Volumes'
'Local Backup | Docker Bind Mounts'
'Cloud Backup'
# (!) It is advised to use below features only for 'daily' backups
#'Daily-backup cleaner'
#'Daily-backup cloud cleaner'
#'Daily-backup archiver'
)
#
declare -x -a functionalityDaily=(
'Local Backup | Home directory'
'Local Backup | Docker Volumes'
'Local Backup | Docker Bind Mounts'
'Cloud Backup'
'Daily-backup cleaner'
'Daily-backup cloud cleaner'
'Daily-backup archiver'
)
To run Docker Volumes & Bind Mounts backups you need Docker environment.
To run Cloud Backup you have to have installed rclone and remote configured (named as homeServerBackup)
For Daily-backup local and cloud cleaners you can specify how many backups you want to preserve
# Choose how many daily backups you want to keep (daily-cleaner settings)
declare -x -i dailyLocal=5
declare -x -i dailyCloud=5
#
Set up your:
- Backup Directory - local destination of backups
- Home Directory - server Home directory + name of it (of the backup)
# Local Backup Directory
declare -x backupDir="path/to/location/where/backup/will/be/stored"
#
# Server Home Directory
declare -x homeDir="/your/home/directory"
#
# Name for backup of Server Home Directory
declare -x homeName="homeYourNameForExample"
To exclude certain sub-directories of Home directory just add it to the array:
# Exclude those homeDir sub-directories from backup
declare -x -a excludeDir=(
'photos' #exclude homeDir/photos
'folder/sub-folder' #exclude homeDir/folder/sub-folder
)
Set up details of your Docker Volumes you would like to backup
# declare -A volumeDocker00=(
# [container]='Container name'
# [volumePath]='Path to volume'
# [name]='Backup .tar file name'
# [stop]=true #or 'false' if you want to backup without stopping the container
# )
#
declare -x -A volumeDocker00=(
[container]='1st-container'
[volumePath]='/path/to/volume'
[name]='1st-container-backup'
[stop]=true
)
#
declare -x -A volumeDocker01=(
[container]='2nd-container'
[volumePath]='/path/to/volume'
[name]='2nd-container-backup'
[stop]=false
)
Set up you Docker Containers of which you would like to backup Bind Mounts. Code assume that you have Bind Mounts located in directory homeDir/Docker/<container name>
. For each of the Docker Container you can choose whether to stop during backup or not.
declare -x bindDocker=(
'3rd-container'
'4th-container'
)
#
# List of Docker Container with Bind Mounts to stop during backup
declare -x bindDockerStop=(
#'3rd-container'
#'4th-container'
)
Set up Gotify server to notify you after each backup
# Gotify website + token, for example: https://push.example.de/message?token=<apptoken>
declare -x GotifyHost="https://push.example.de/message?token=<apptoken>"
#
# Title of Notification
declare -x GotifyTitle="yourServerName"
Backup of the server could couse high disk backlog and therefore spam notifications from Netdata about it (if you have that tool installed on the server). You can disable those notifications for the time of the backup script.
# Replace <apptoken> with Netdata 'api authorization token'
# that is stored in the file you will see in the following entry of http://NODE:19999/netdata.conf:
# [registry]
# # netdata management api key file = /var/lib/netdata/netdata.api.key
declare -x NetdataAuthToken="<apptoken>"
#
# Change to 'true' to enable Netdata silencer
declare -x NetdataSilencer=false
If you would like to silende Netdata backlog notification not only for the time of the backup but also other scheduled activities (like automatic updates) it is better to disable those directly in the crontab:
# Disable Netdata disk.backlog notifications during scheduled activities
0 0 * * * docker exec netdata curl -s "http://localhost:19999/api/v1/manage/health?cmd=SILENCE&context=disk.backlog" -H "X-Auth-Token: <apptoken>"
# Daily Backups
0 1 * * * cd /<example directory> && ./homeServerBackup.sh -t daily
# Re-enable Netdata silenced notifications
0 3 * * * docker exec netdata curl -s "http://localhost:19999/api/v1/manage/health?cmd=RESET" -H "X-Auth-Token: <apptoken>"
home-server-backup
is distributed under the GNU General Public License version 3.0 license. See LICENSE for more details.