Lxc export and crontab

Hi,

Ubuntu 18.04
LXD 4.12 (snap)

I’m not sure it’s LXC problem, but I need little help.

This is my backup script:

# Basic shell script to backup required LXD parts ##
## Backup and restore LXD config ##
## Today's date ##

#sudo -i

NOW=$(date +'%Y-%m-%d-%H-%M')

## Dump LXD server config ##
lxd init --dump > "/mnt/backupusb/lxd/lxd.config.${NOW}"

## Dump all instances list ##
lxc list -c n --format csv > /mnt/backupusb/lxd/lxd.instances.list

## Remove specific from backup list
#sudo sed -i -e "s/NAME_CONTAINER//g" /mnt/lxd/lxd.instances.list

## Make sure we know LXD version too ##
snap list lxd > "/mnt/backupusb/lxd/lxd-version.${NOW}"

## Backup all Instances
for i in $(cat /mnt/backupusb/lxd/lxd.instances.list)
do
     echo "Making backup of ${i} ..."
     lxc export "${i}" "/mnt/backupusb/lxd/${i}-backup-${NOW}.tar.xz" --optimized-storage
done

## Delete mnt older than 7 days
sudo find /mnt/backupusb/lxd/* -mtime +7 -exec rm {} \;

and my cron for my user (user belong to group lxd)
0 4 * * * sh /opt/backup_lxd.sh >/dev/null 2>&1

This is work:

## Dump LXD server config ##
lxd init --dump > "/mnt/backupusb/lxd/lxd.config.${NOW}"

## Dump all instances list ##
lxc list -c n --format csv > /mnt/backupusb/lxd/lxd.instances.list

## Remove specific from backup list
#sudo sed -i -e "s/NAME_CONTAINER//g" /mnt/lxd/lxd.instances.list

## Make sure we know LXD version too ##
snap list lxd > "/mnt/backupusb/lxd/lxd-version.${NOW}"

But this is not work:

## Backup all Instances
for i in $(cat /mnt/backupusb/lxd/lxd.instances.list)
do
     echo "Making backup of ${i} ..."
     lxc export "${i}" "/mnt/backupusb/lxd/${i}-backup-${NOW}.tar.xz" --optimized-storage
done

BUT!
When I simply do at any time:
sh /opt/backup_lxd.sh
No problem, I have backup on my external drive.

It’s certainly stupid thing I missed…

Thanks

I found solution in this post:

In cronjob, $PATH is not like $PATH in bash. So I need to add /snap/bin/ to use lxc.

/snap/bin/lxc export "${i}" "/mnt/backupusb/lxd/${i}-backup-${NOW}.tar.xz" --optimized-storage

Hope this help.

Thanks