For some of the newer devices equipped with less storage, at least compared to the immense storage requirements nowadays, finding the storage space for your rather sizable backup becomes harder and harder. Some of you might have noticed that our Fuga Cloud platform comes with a rather copious amount of storage and have wondered “Why can’t I use that storage for my rather sizable back-up?”.
If this was the case, then wonder no longer for this handy tutorial will describe the process* in which we will leverage the storage potential of Fuga Cloud to ensure your data is safely stored on your Volume.
[*] Provided that you are working on a Unix machine (like Linux or MacOS), sorry, no Windows. Also, if you are allergic to the command line, this tutorial might be a little bit hard to digest.
- A Fuga cloud Account
- OpenStack Credential
- OpenStack CLI tools installed
(this comes in 3 different formats: OpenRC.sh / Clouds.yaml / Dockerfile)
Step 1: Installing Restic
How you get Restic on your system differs per OS, and if yours is among the following you are in luck as this is a whole lot easier. After step 1.1 go to step 2.
Step 1.1: Using a binary
# Apple MacOS
$ brew install restic
# Arch Linux
$ pacaur -S restic-git
# Nix & XixOS
$ nix-env --install restic
$ apt-get install restic
Step 1.2: Installing manually
If yours wasn’t there then we’ll compile it ourselves.
Step 1.2.1: Install Go
As Restic is written in Go, we’ll need the Go language, paste the following into your console and press enter to execute the command:
$ wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz
$ sudo tar -xvf go1.9.2.linux-amd64.tar.gz
$ sudo mv go /usr/local
$ export GOROOT=/usr/local/go
$ export GOPATH=$HOME/go
$ export PATH=$PATH:$GOROOT/bin
$ go version
If all went well you should now have some text on your console informing you that Go version 1.9.2 has successfully been installed.
Step 1.2.2: Compiling Restic
Next, clone the git repository of Restic and compile it.
$ git clone https://github.com/restic/restic
$ cd restic
$ go run build.go
Step 2: Moving restic to /bin
If it successfully compiled you should have a file named Restic in your current directory, move this to the folder which holds the system binaries so it can be easily executed from anywhere.
$ sudo mv restic /bin
If this completes, typing “restic” into the console and pressing enter should return a large amount of text telling you how to use the restic command. If it doesn’t, try closing and reopening the console.
Step 3: Setting up Restic
The first step is sourcing the RC file we’ve got in step one.
$ source [Name of your RC file].sh
Following this you should be able to run:
restic -r swift:[Name of Container]:/path(path is optional) init
This creates a container in Swift with the name you set in [Name of Container] with a subdirectory named path.
$ restic -r swift:Back_up:/work init
The above code creates a Container named “Back_up” with a subfolder named “work” which is usable as a backup location.
# Note! Running any sort of Restic command which connects to a backup location prompts you for a password,
# this can be automated by setting an environment variable RESTIC_PASSWORD, using:
$ export RESTIC_PASSWORD="ThisPassword123"
If you add these lines to .bashrc, like above, you don’t have to insert these commands every time you want to back up.
Step 4: Backing up
With the repository set up, it is now only a matter of backing up.
$ restic -r swift:[Name of Container]:/path(path is optional) backup [Folder or file]
By running this command you restore the backup file or folder (you’ve done this in step 4) to the location indicated by –target. Restore requires either the snapshot ID (returned from when you updated the data) or the word “latest” to retrieve the most recent version. Execute the command and sit back while the data is retrieved, mind that unlike the backup Restic doesn’t provide a progress bar but something similar can be achieved by using the following:
Step 5: Restoring
With the data now safely stored in the Swift object store, it is now only a matter of retrieving the data when you need it, using this command:
$ restic -r swift:[Name of Container]:/path(path is optional) restore [id or latest] --target [Folder or file]
By using this command you restore the backup file or folder(you’ve done this in step 4) to the location indicated by –target. Restore requires either the snapshot ID (returned from when you updated the data) or the word “latest” to retrieve the most recent version. Execute the command and sit back while the data is retrieved, mind that unlike the backup Restic doesn’t provide a progress bar but something similar can be achieved by using the following:
$ watch -1n du -s [Folder which is being restored]
This will run in your current console, so I would recommend that you open a second console, to exit the command simply press CTRL+C to close watch.
Step 6: Rince and repeat
With the knowledge to create repositories, backup and restore your data using Swift, I would suggest that you take a look at the Restic documentation and see what else it can do.
I would suggest looking into Cron a time-based Unix utility to run backups automatically.