Hi,
My goal was to allow my brother to backup is owncloud on a permanent usb key directly from the yunohost admin. I write here how I proceed, but I want to warn you these changes could not be compatible with future yunohost version. So you need to understand each step. In my case I have used a FAT32 key, it is a little more difficult, but I think it can work with ext3 or ext4 usb key more easily.
Repair auto mount
Firstly, you need to have a functional auto mount, old yunohost version was using udisks and udisks-glue to do that, but it seems on my image it doens’t work . So I have fixed with udev.
Udev was already install in my case, but I suggest you to check it by doing
sudo apt-get install udev
Next add udev rules to auto mount and auto unmount. Note that with this script all fat32/ntfs usb key will be mounted with admin (1007) as owner.
sudo vi /etc/udev/rules.d/11-media-by-label-auto-mount.rules
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"
# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
# Global mount options
ACTION=="add", ENV{mount_options}="relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,uid=1007,gid=1007,umask=002"
# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
# Exit
LABEL="media_by_label_auto_mount_end"
Restart udev
sudo systemctl restart udev
sudo systemctl status udev
At this step if you plug your usb key you should see them in /media
root@olinux:/home# sudo ls /media
NAME_USB_KEY
Move yunohost backup dir and create a symbolic link
The idea is then to replace the standard /home/yunohost.backup dir by a symbolic link.
sudo mkdir -p /media/NAME_USB_KEY/home
sudo mv /home/yunohost.backup /media/NAME_USB_KEY/home/
cd /home/
sudo ln -s /media/NAME_USB_KEY/home/yunohost.backup yunohost.backup
(Optional) Make yunohost backup compatible with fat32
You need this step only if your usb key doens’t support permissions typically if it is formatted with FAT32 (or maybe NTFS).
Unhappily, at this step there is a bug when you try to run backup create yunohost command. It is because yunohost backup command is not for the moment compatible with FAT32. The issue is that ynh_backup command do a cp -a
command. But FAT32 can’t preserve user/group permission and can’t preserve symbolic link.
I have fixed it by modifying this script. That 's why you should be carreful because in future yunohost version this script could be changed.
Inside /usr/share/yunohost/helpers.d/filesystem line 54 replace
eval $SUDO_CMD cp -a "${SRCPATH}" "${DESTPATH}"
by
eval $SUDO_CMD cp -RL "${SRCPATH}" "${DESTPATH}"
Test it
Forstly, you can test by excluding apps of the backup. It is shorter than waiting some backup like owncloud.
yunohost backup create --ignore-app
And next try with the all data
yunohost backup create
If all goes well, you could test on the web admin.