Published

  • YunoHost
  • VirtualBox
  • Backup
  • Debian
  • Shared folders

A backup that lives inside the virtual machine it protects isn't much of a backup. If the VM's disk is lost or corrupted, the archives go with it. A simple fix with VirtualBox is to let YunoHost write its archives straight into a folder on the host, using a shared folder.

This guide assumes a YunoHost (Debian) VM in VirtualBox. Run the commands in the VM as root (or prefix them with sudo).

Why share only the archives folder

YunoHost stores its backups in /home/yunohost.backup/archives. Share only that subfolder, not the whole /home/yunohost.backup directory: while building an archive, YunoHost also uses /home/yunohost.backup/tmp as a working area, and that staging step needs a normal Linux filesystem, not a VirtualBox shared folder.

1. Install the VirtualBox Guest Additions

The Guest Additions provide the vboxsf driver that makes shared folders work. First install the build tools. dkms is optional but recommended, as it rebuilds the modules automatically after kernel updates.

apt update
apt install build-essential dkms

Then, in the VirtualBox window of the VM, choose Devices → Insert Guest Additions CD Image, and run the installer inside the VM:

mount /dev/cdrom /media/cdrom
cd /media/cdrom
./VBoxLinuxAdditions.run

Alternatively, skip the CD image and install the Debian package instead:

apt install virtualbox-guest-utils

Reboot the VM afterwards:

reboot

2. Create the shared folder in VirtualBox

On the host, create a folder that will receive the archives, for example an archives folder inside wherever you keep your backups. Then open the VM's Settings → Shared Folders → Add and set:

  • Folder Path: the archives folder on the host.
  • Folder Name: for example yunohost_archives (you will use this name below).
  • Auto-mount: enabled.
  • Make Permanent: enabled.

3. Mount it inside YunoHost

Create the target folder if it doesn't exist yet, then mount the share on it:

mkdir -p /home/yunohost.backup/archives
mount -t vboxsf yunohost_archives /home/yunohost.backup/archives

Check that it worked:

findmnt /home/yunohost.backup/archives
ls -la /home/yunohost.backup/archives

Mounting at every boot

With Auto-mount enabled, VirtualBox should remount the share on its own. If it doesn't, add this line to /etc/fstab:

yunohost_archives /home/yunohost.backup/archives vboxsf defaults 0 0

and test it:

mount -a

Alternative: let /etc/fstab do all the work

If you want more control over ownership and boot behaviour (for instance, the VM should still boot when the host share is unavailable), skip VirtualBox's Auto-mount and mount the share through /etc/fstab only:

  1. In VirtualBox, set Auto-mount to disabled for yunohost_archives. Keep Make Permanent enabled.
  2. Make sure the vboxsf module is loaded early at boot:
    echo vboxsf | sudo tee -a /etc/modules
  3. Use this line in /etc/fstab instead of the one above:
    yunohost_archives /home/yunohost.backup/archives vboxsf uid=0,gid=0,dmode=0700,fmode=0600,nofail 0 0
  4. Run mount -a, then reboot once to confirm the mount comes back cleanly.

4. Fix access permissions

VirtualBox shared folders normally grant access through the vboxsf group. Check who owns the folder:

ls -ld /home/yunohost.backup/archives

If it is owned by root:vboxsf, add your YunoHost user to that group (replace ynh_username with the real username):

usermod -aG vboxsf ynh_username

Log out and back in, or reboot, for the change to apply. Verify it with:

id ynh_username

Don't rely on chmod or chown to change permissions on the share: they are governed by the mount options, or by uid= and gid= in /etc/fstab if you use the alternative setup.

Try it out

Create a backup from the YunoHost admin (Backups → New backup) or from the command line, then look in the host folder: the new archive should appear there.

yunohost backup create

Comments

Post a comment on “Back up a YunoHost VM to a folder on the host”

You may use <b>, <i>, <u>, <s>, <code>, <pre>, <ul>, <ol>, <li> and <blockquote>. Web addresses become links; [img]address[/img] shows an image on request.

About you (all optional)

Never shown. Only used to notify you of replies.

Lets you edit or delete your comment later, from any browser, by logging in with the same name.

To post, like or reply, please complete this security check by Cloudflare Turnstile.

The security check needs JavaScript. Please turn it on to post, like or reply.

Logging in with the name and password of earlier comments lets you edit them.

0 comments

No comments yet. Be the first to comment!