An easy Backup Script for Incus :-)

Hello there, and first of all, thanks to Stephane for his great work !! :slight_smile:

I recently came to run a whole bunch of VMs over differents cluster of servers using Incus, and faced a little problem regarding how to automate backups. I mean, simply enough, to be troubleshooted by anyone, even me !!

I went up with this little script, that lets me backup one entire cluster member, to another, automatically.


#to save an entire server, first, export list of instances : 
incus list location=$1 -c n -f csv > savetodo.txt

#then define the date format to use in file generated-name, and the path to the list file generated above:
bkpdate=`date "+%Y%m%d"`

#Finally, do the things !
while read -r line
  incus export $line $line.$bkpdate.bkp.xz
done < "$input"

One can run this script on each servers, with the next-server name as argument, for exemple :

./ <next-membername> 

I use XZ compression for backups, but as compressor isnโ€™t really fast, i set backup compression settings as follow, for our 2*12core cpu servers, no-one can barely notice when itโ€™s backuping :

backups.compression_algorithm=xz -8 -T8

One have to notice, that backup is ran in two steps :

1 - The server hosting the VM/CT performs the backup, and compress the datas.
2 - When the tarball is complete, itโ€™s sent to the server where backup are ran.
3 - When upload is complete, the backup process resumes to the next VM/CT

Hope it helps :slight_smile:

Best regards,


Cool. I think you should be able to avoid creating the temporary file, something like this:

bkpdate="$(date "+%Y%m%d")"
incus list location="$1" -c n -f csv |
while read -r line
  incus export $line $line.$bkpdate.bkp.xz