Whatbox Logo
Login for certain variables to be updated with your slot's information

Wiki > Backing up your slot's configuration and torrent files

While it's not easy to backup your entire slot without another server or computer with equal or greater storage, it may be desirable for you to have a backup of your slot's configuration (Plex library and plugins, autodl-irssi filters, cron jobs, etc.) and .torrent files. Below is one way you can backup your slot's configuration and torrent files.

Before starting

  1. Connect to your slot through SSH.
  2. Create a folder to store the backup. mkdir /home/user/backups
  3. Make sure you have a scripts folder. mkdir /home/user/.scripts

What to back up

The command to create a backup of your entire slot is:

tar -zcvf /home/user/backups/whatbox-backup.tgz /home/user/* /config/user/*

However, you'll most likely want to exclude some paths from the backup. Below are some examples of things you should exclude:

Your media files

You'll want to exclude /home/user/files and any other media folders so you don't exceed your slot's storage because of the backup's file size.

Plex Cache

You should safely exclude Plex's Cache directory which will save space and time in the backup process, as recommended by Plex. This folder is located at /home/user/Library/Application Support/Plex Media Server/Cache

Mounted filesystems

External filesystems mounted with tools such as rclone or plexdrive should be excluded from the backup.

Example backup command

After determining what you want to exclude, use the --exclude flag to specify these paths. Here is an example command that employs this flag:

tar --exclude='/home/user/files' --exclude='/home/user/Library/Application Support/Plex Media Server/Cache' --exclude='/home/user/mnt' -zcvf /home/user/backups/whatbox-backup.tgz /home/user/* /config/user/*

Note: once you have your command, be sure you know what it does and try a test backup before proceeding. After running, you can:

  • Check the size of your backup. du -sh /home/user/backups/whatbox-backup.tgz
  • List the contents of the archive without extracting it. tar -tvf /home/user/backups/whatbox-backup.tgz

Specifying paths to back up instead of excluding

You can alternatively give tar a list of specific paths you'd like to back up using the -T flag instead of excluding paths:

  1. Make a file to be used by the backup command. touch /home/user/.scripts/backup_paths.txt

  2. Edit the file and enter the paths you want to back up. nano /home/user/.scripts/backup_paths.txt
    Here is an example backup_paths.txt:

     /config/user
     /home/user/.bashrc
     /home/user/.config
     /home/user/.autodl
     /home/user/html
     /home/user/.irssi
     /home/user/.scripts
     /home/user/.ssh
     /home/user/Tautulli/config.ini
     /home/user/Tautulli/tautulli.db
     /home/user/tautulli_restart.cron
     /home/user/Library/Application Support/Plex Media Server
    
  3. Save the file with CTRL+x, y, and Enter

  4. Then, using the -T flag, the new tar command would look something like this:

     tar --exclude='/home/user/Library/Application Support/Plex Media Server/Cache' -zcvf /home/user/backups/whatbox-backup.tgz -T /home/user/.scripts/backup_paths.txt
    

    For this example, we still had to exclude Plex's Cache directory as it is inside the main Plex directory.

Transferring the backup

With rsync

rsync -avz --progress /home/user/backups/whatbox-backup.tgz username@some_server_or_ip:/path/to/backup/dir/

The breakdown of the rsync command is as follows:
rsync - Runs the syncing program rsync
a - archive mode; equals -rlptgoD (no -H,-A,-X)
v - increase verbosity
z - compress file data during transfer
--progress - show transfer progress

Other options

See the wiki for other options, such as Syncthing and FTP/SFTP.

Creating a backup script

Combining the above tar and rsync commands, you can create a backup script.

  1. Create a new script file. touch /home/user/.scripts/whatbox-backup.sh

  2. Edit the file and enter the text below. nano /home/user/.scripts/whatbox-backup.sh

     #!/bin/bash
    
     # backup cron jobs
     crontab -l > /home/user/.config/crontab.txt
    
     # create backup archive
     echo "tar command goes here"
    
     # backup to another server
     echo "rsync command goes here"
    
  3. Replace the echo lines with your backup and transfer commands from above.

  4. Save the file with CTRL+x, y, and Enter

  5. Make the script executable. chmod +x /home/user/.scripts/whatbox-backup.sh

You can run the script by entering: /bin/bash /home/user/.scripts/whatbox-backup.sh

Automating backups with cron

You can tell cron to automagically run your script at a specified time.

  1. Open your crontab file. crontab -e

  2. Add the following text to the bottom of the file.

     # Whatbox backup script
     @weekly /bin/bash /home/user/.scripts/whatbox-backup.sh > /dev/null 2>&1
    

    Note (1): You can replace the @weekly part with whatever frequency you'd like. See the cron wiki for more information.
    Note (2): Each run of the script will overwrite the previous backup, so you will always have the latest one.

  3. Save the file with CTRL+x, y, and Enter