HOWTO backup LXD containers via rclone

I use rclone to backup my LXD containers to an encrypted google drive.

I use monit to check backups succeeded by checking the mtime on touched files as rclone unfortunately doesn't properly handle mtime on directories yet. Need to rm the files first as touching existing files to change their mtime doesn't work with rclone mounted volumes.

Hope this is helpful to someone!

LXD: https://linuxcontainers.org/lxd/introduction/
Monit: https://mmonit.com/monit/
lxdbackup script: https://github.com/cloudrkt/lxdbackup

Shell script in cron:

#!/bin/sh

BKUPDIR="/media/encvol/Backups/Containers"
BKUPSCRIPT="/root/scripts/lxdbackup.sh"
LXC="/snap/bin/lxc"

## Check for encvol mount
if findmnt --raw --noheadings encvol: /media/encvol ; then
        echo "encvol is mounted!\n\n"

for contner in $($LXC list -c n --format csv); do
        echo "Backing up $contner container to $BKUPDIR/$contner ...\n"
        if $BKUPSCRIPT $contner ; then
                rm $BKUPDIR/$contner/backup_time && touch $BKUPDIR/$contner/backup_time
        else
                echo "$contner backup failed!"
        fi
        echo "\n\n"
done

## If encvol not mounted, error message
else
        echo "encvol not mounted!\n"
        exit 1
fi

Does the modtime of the file not change? If it does it shouldn't matter about the directory.

I know that if you mount a file on linux the modtime of the file doesn't get updated, so maybe it is that.

You could also use --checksum to check for differences if the modtimes aren't working.

It does, but the filename changes with each backup and there's no way to tell monit to look for the latest updated file inside a directory. That's why I just create a statically named one. It's not exactly elegant, but it works.

1 Like

I see :slight_smile: Thanks for explaining.

1 Like

Sure. Thanks for making rclone!!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.