Daily backup script

@tomp could u help?

What is on line 9?

This looks like you don’t have lxc in the path. Did you try with absolute path to the lxc binary?

cron may not have /snap/bin/ in its PATH, so you may want to use /snap/bin/lxc directly in your crontab.

@stgraber @matjaz @Jimbo here is my script

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

exec >> /var/log/backup.log
exec 2>&1

BACKUP_DIR=/mnt/Image
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

BACKUP_NAME=${HOST}-$(date +"%Y-%m-%d_%H-%M-%S")
lxc snapshot ${HOST} auto-backup
lxc publish ${HOST}/auto-backup --alias ${BACKUP_NAME}
lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}.tar.gz
lxc image delete ${BACKUP_NAME}
lxc delete ${HOST}/auto-backup
done

Now olz tell me where I will change ?

What @stgraber was saying change this, but you said error was on line 9, so I think this is a different script.

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

I changed the script for you here, did you try this?

1 Like