Daily backup script

I need a script for this procedure for daily backup. backup0.tar.gz file will store in a remote loacton. is it possible?

lxc export my_container backup0.tar.gz

Use rsync or mount an NFS drive and export the backup there?

I edited your initial post per How to best ask questions on this discussion forum

I need to export listed lxd not all lxd . Suppose I have 20 container in my lxd server but I need to backup export listed 10 servers. Is it possible?

I dont really follow what you are asking,

Do you need to backup 10 containers or do you need to copy your backups to 10 different servers?

I need to selected a backup. But all scripts for all container backup. There is no script for selected container backup.
Could u help me plz?

My software can do all this for you LXDMosaic

If you want to go with a script you could do something like this;

On the containers you want to backup daily you could set a user key like

lxc config set INSTANCE_NAME user.daily-backup=1

Then in your script you could do;

#!/usr/bin/env bash
#set -ex

HOSTS=($(lxc list -c n --format csv))

for HOST in "${HOSTS[@]}"
do
  # Check if the backup key is set
  backupKeySet=$(lxc config get ${HOST} user.daily-backup)
  # Returned empty so it doesn't need to be backed up
  if [ -z "${backupKeySet}" ]; then
    echo "skipping ${HOST}"
    continue
  fi

  echo "backing up ${HOST} ..."
  # Add your backup code here
done
1 Like

Is this backup work for LXD 3.0.3? Cause when I am trying it shows

root@lxd:~# lxc config set test user.daily-backup=1
Error: cannot set ‘test’ to ‘user.daily-backup=1’: unknown key

Setting of “user defined” user keys was only added in September 2020 (here), so I doubt its been back ported to 3.0.3 & this script wont work!

then how can I export import from from 3.0.3 to latest? Have any idea?

Migrating from version to 3.0.3 to the latest or backing up to the latest?

Backup server 4.12 in ubuntu 20.04. But surprisingly server 3.0.3 cann’t added this server for remote host.

maybe @tomp can help here!

Ok. I am talking with him another issue :frowning:

If you export the container as a file (using lxc export) then you can transfer and re-import them to a newer host (using lxc import).

I know but lxc export ,import, even image export import doesn’t work but my container works fine.

@turtle0x1 is ur mosaic support lxd 3.0.3?

It did, I dont test against 3.0.3 but it should still do! Im not sure it will be able to move the instances though if LXD cant!

I wanna trying to add remotr host by mosaic, cause i didn’t add from lxd :frowning:

I have used ur script with some modification and it works fine when I am run manually. But when I am set it into crontab this script doesn’t work . what is the issue?

my file permission
-rwxr-xr-x 1 root root 726 Mar 29 12:14 daily.sh

crontab -e
38 09 * * * /home/daily.sh

It shows in log file “/home/daily.sh: line 9: lxc: command not found”

Where is fault?