Restoring a directory from Vorta
Vorta is a client program for MacOS and Linux computers that provides a graphical user interface (GUI) for Borg, a powerful backup tool that is normally used in command-line. Borg is a deduplicating backup program, which means once you initialize a repository somewhere (like on an external hard drive) and take your first backup, it will only copy files that have changed since the previous backup. This allows users to take backups as frequently as they want without it taking up an insane amount of space. I use Vorta on my Fedora desktop to take hourly backups of the home directory to a USB HDD, as an insurance for my incompetence at system administration.
Vorta provides a simple way to restore all or some of your backups. It is simple to access any of the available backups in my repository and select a file or whole directory tree to recover, and then tell Vorta where I want to put the recovered files. A unique case arises: if I wanted to take the entire home directory tree from a backup and put it on a system in such a way that the backup completely replaces the home directory tree on the system, how would I do that? Vorta only provides two ways to recover: You can copy the directory tree and place it under an existing home directory, or you can mount it to your file system as if it were a drive. Neither are the desired outcome, so this documents my attempt at a solution in Fedora. I am sure there is a better way to do this.
Assumptions: The general idea here is that you have a backup of a directory tree, and you have a somewhat blank system that you want to drop it into. The original system where the backup was taken may or may not still exist (i.e., it could have been damaged or deleted.) The steps in this tutorial should not cause undesired loss to files or backups, but this tutorial is published with no warranty.
Note: Use pwd
liberally in the command-line to verify you are actually working in the directory you think you are. This is always good practice.
1: Install Vorta on the system where you will add the backup to. This can be done in command-line:
$ flatpak install flathub com.borgbase.Vorta
2: Connect the drive containing the repository to the machine. If the system (meaning OS/virtual machine) is not the same as where the backup was created, you will need to modify the repository's permissions. Use lsblk
in the command-line to list block devices connected to your computer, and look for your drive. You should see something like /run/media/$USER/drive-name
. ($USER
is the BASH variable for the logged-in user.) Change into that directory and type ll -a
. The permissions for the backup directory will likely be drwx------
, which means only the directory owner can read, write or execute. But since this is a different system, you are not recognized as the owner. To temporarily change permissions such that Vorta can use the repository, I did:
$ sudo chmod -R 777 <directory-name>
The -R flag applies it to the directory and everything inside, while the code 777 changes the permissions to drwxrwxrwx
, which means anyone can read, write or execute. (I guess there are less free-for-all restrictions you could use here, but this is what I did and the system is only used by one person anyway.)
3: After the last step, go back to Vorta, where you should be able to add the repository just fine. You can then pick the backup you want to use and select the directory tree to restore. In my investigation, I only restored the Documents directory tree since my virtual machine did not have room for the whole home directory. Pick the tree, and then tell Vorta where you want to plop it. The tree will be copied into the directory you pick. Note that it will actually copy over any parent directories. For example, I restored the Documents directory, but that actually copied home>user>Documents.
- The tree will likely have been copied with the wrong owner, so that needs to be changed again. In the command-line, you can use
chown
to change a directory's ownership. After changing into the directory containing the restored tree, I used:$ sudo chown -R $USER home
I used "home" here because it was the parent directory containing the restored backup, NOT the actual home directory of the system I was using. This is a relative path. The command above changes the owner of the directory to be whoever is currently logged in.
4: The desire now is to make it so that the files in this recovered tree are sent up to the parent tree, the REAL Documents directory. I don't want to have to click "Documents", then "home", then "user", then "Documents" just to get at my files. So in the command-line, cd into the bottom directory (the one with the files you want to move). Then use:
$ mv * ~/Documents && cd ~/Documents && rm -r home
The above command does three things in succession. It moves everything in the bottom directory to the real Documents directory, the one that is just under /home/$USER/
, as on any Fedora system. It then changes that real directory to be the current directory. Then it removes the now-vacant recovered tree. You should only use that last part if you are sure you don't need the recovered tree anymore. It will not remove your actual home directory, /home/$USER/
, because relative paths only work for directories "under" your current working directory. In this case I was in /home/$USER/Documents
, so a relative path cannot reach it.
5: (Optional)
- Change the backup repository back to the permissions it had before. Cd into it and use,
$ sudo chmod -R 700 <directory-name>
The 700 code corresponds todrwx------
. - If the original system where the backups came from still exists and you want to continue taking backups on it, go into Vorta on the secondary system and unlink that repository.
So, that's how I did it.