Rsync

Rsync is a very robust CLI tool that provides fast incremental file transfer with many features:

Initial Setup

Rsync is a very robust CLI tool that provides fast incremental file transfer with many features:

https://rsync.samba.org/

Pulling files from your slot using Rsync

Given the fact Rsync is included on Most if not all modern Distros, It is simple to begin pulling files from your Ultra.cc slot. First login to the machine you plan on storing the pulled files. Not your Ultra.cc Slot

rsync -aHAXxv --numeric-ids --info=progress2 --bwlimit=20000 user@lwxx.usbx.me:/home/username/download/ /home/targetusername/path/to/save/to

Rsync will now ask you if your hostkey is correct, If this is your first time connecting this is totally normal type yes and hit Enter. This will now prompt you for your Ultra.cc SSH Password.

Argument Effect
-a Tells rsync to recursively copy everything
-H This tells rsync to look for hard-linked files in the source and link together the matching files on the target
-A Tells Rsync to keep permissions the same on target
-X Tells Rsync to keep any file attributes the same on target
-x Tells Rsync to avoid copying Mounts and fuse based filesystem
-v show all output
--bwlimit=20000 Apply a Bandwidth limit of 20 Megabytes
user@lwxx.usbx.me Fill this with your Ultra.cc Username and Server address

Uploading files to your slot using Rsync

Uploading to your slot is just as simple as downloading from your slot to a new location. Login to your Ultra.cc Slot rsync -aHAXxv --numeric-ids --info=progress2 --bwlimit=20000 -e "ssh -p portnumberhere" username@remoteip:/home/remoteusername/ ~/Rsyncdrop

Please note portnumberhere this is added so if your target machine is using an ssh port that is not the standard 22 you can insert it here, otherwise please enter 22 in its place

Like when Pulling files from your Ultra.cc slot, you will be prompted to confirm your hostkey and remote machines SSH Password.

Creating a Full copy of a Userspace from a remote Server

You will find this familiar if you have followed our provider migration guide, However now is a good time to refresh yourself on the Process as it can be adjusted for many different paths etc.

So exactly like before when uploading files to your Ultra.cc Slot you will need to run this from your slot.

We recommend running a screen if you are copying a large directory structure.

screen -S usercopy

rsync -aHAXxv --numeric-ids --info=progress2 --bwlimit=20000 -e "ssh -p portnumberhere" username@host:/home/remoteusername usercopy

Press CTRL A+D to detach leaving the transfer running you can reattached with screen -rd usercopy

This will place all of your remote servers /home/username directory to a folder called usercopy on your Ultraseedbox Slot.

Ultra.cc External Backup Script using Rsync

Adding SSH Keys for passwordless connection

First you will need to create a Key to be later imported to the destination host.

Creating Public and Private Keys

$ ssh-keygen
Generating public/private rsa key pair.
$ ssh-keygen -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home/.ssh/id_rsa):
$ ssh-keygen -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
$ ssh-keygen -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /your_home/.ssh/id_rsa.
Your public key has been saved in /your_home/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:x23Tr+Ee5TlowA+U9HEquagnog3O09EYHQ346WY usbdocs@usbdocs
The key's randomart image is:
+---[RSA 4096]----+
|=.=. . o+..      |
|.B  o  .oo.      |
|o.o  oo  o       |
|.+ . oo ...      |
| .. .  +S+ .     |
|.      =o==      |
|.o.   o.=o.      |
|o... oE.+o       |
| .. .++..o.      |
+----[SHA256]-----+

Copying the new keys to the destination host

Type in ssh-copy-id username@destinationip

$ ssh-copy-id usbdocs@85.145.22.545
$ ssh-copy-id destinationusername@85.145.22.545
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/usbdocs/.ssh/id_rsa.pub"
The authenticity of host '85.145.22.545 (85.145.22.545)' can't be established.
ECDSA key fingerprint is SHA256:9mQKWg1PVPZtxcDASEDdasawrqw.
Are you sure you want to continue connecting (yes/no)?
$ ssh-copy-id destinationusername@85.145.22.545
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/usbdocs/.ssh/id_rsa.pub"
The authenticity of host '85.145.22.545 (85.145.22.545)' can't be established.
ECDSA key fingerprint is SHA256:9mQKWg1PVPZtzZ6d5nDjcWUb/Flkuq5VHYRrvwTeRTE.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
kbguides@kbguides.lw902.usbx.me's password:


Number of key(s) added: 1

Now try logging into the machine, with: "ssh '85.145.22.545'" and check to make sure that only the key(s) you wanted were added.

The Shell script

This Shell script will allow for an automatic backup of important information related to the configuration of your applications excluding Plex.. It can then be configured to store it or either google drive or a local folder on your Ultras Slot.

Initial Setup and Configuration

Your first step is to find the full path of your home directory

pwd

Something like this will be outputted be sure to make a note of it :

/home1/usbdocs

then create three new folders, one may already exist this is fine mkdir ~/lock mkdir ~/scripts mkdir ~/autobackup

Then you need to enter the new folder called scripts

cd ~/scripts

And create the script file

nano backup.sh

Paste the following lines into it :

#!/bin/bash
exec {lock_fd}>/home1/usbdocs/lock/BackupLock || exit 1
flock -n "$lock_fd" || { echo "ERROR: flock() failed." >&2; exit 1; }
if [ -z "$STY" ]; then exec screen -dm -S autobackup /bin/bash "$0"; fi

DATE=$(date +%Y-%m-%d-%H%M%S)
tar --exclude="$HOME"/.config/plex -czvf "$HOME"/autobackup/MyUSBbackup-$DATE.tar.gz "$HOME"/.apps "$HOME"/.config



rsync -aHAXxv --numeric-ids --info=progress2 -e "ssh -p portnumberhere" /home1/usbdocs/autobackup username@destinationip:/home/username/destination/folder


flock -u "$lock_fd"

Save it by pressing Ctrl+X then Y then Enter.

You will need to change the paths home1/usbdocs to match your own home and username. You will also be required to change destinationip to match your destination

Testing

So to test first we navigate to ~/scripts folder we made earlier

cd ~/scripts

Then we need to allow the backup.sh permissions to run

chmod +x backup.sh

And finally, run it

./backup.sh

If all went well * tar -ztvf ~/autobackup/.tar.gz should show a bunch of files starting with /home/username/.config and /home/username/.apps inside.

If the script is running and you were to rerun it, you may see an error message “Flock Failed” this is a file lock to stop multiple downloads running and is normal. If you are sure it isn’t running you can delete the lock file from ~/lock. You can also check the progress of the backup script, which is running in a screen with the command screen -rd autobackup

If all is well after the test, we can automate the check via crontab

Open crontab with

crontab -e

You may have a choice of editors. We recommend Nano

Inside the crontab add a single line under everything else in the file that looks like this

0 0 */3 * * /home/usbdocs/backup.sh

Save it by pressing Ctrl+X then Y then Enter.

The script will now run every 3 days, checking for files that have changed and syncing them to the destination folder