Automatic Backup of Configuration Files

@silvrr yes, i have all configurated shell also.
i installed my HA from image hassbian.
my files are inside /home/homeassistant/.homeassistant

i use command:
sudo mkdir/mnt/usbdrive/backup/

and folders are OK in /mnt

but when i run the scrip… my PEN is empty.

$ cp -a /home/homeassistant/.homeassistant/configuration.yaml “/mnt/usbdrive/backup/configuration.yaml-$(date +”%m%d%Y-%H%M")"
cp: cannot create regular file ‘/mnt/usbdrive/backup/configuration.yaml-01192017-1903’: Permission denied

The issue is likely then that the first part of the CP command is wrong. The CP command says copy from one directory to another.

If you installed Hassbian then /home/hass/.homeassistant/ does not exist. Im suprised it didn’t notify you in the terminal window.

Try:

backup_configuration: cp -a /home/homeassistant/.homeassistant/configuration.yaml "/mnt/usbdrive/backup/configuration.yaml-$(date +"%m%d%Y-%H%M")"

@rpitera or @fabaff any idea why I cannot edit the orignal post in this thread anymore? I was going to add a note as hass is no longer the user so most of the directory information should be updated. Its locked though, I noticed it on a few threads.

@silvrr

$ cp -a /home/homeassistant/.homeassistant/configuration.yaml “/mnt/usbdrive/backup/configuration.yaml-$(date +”%m%d%Y-%H%M")"
cp: cannot create regular file ‘/mnt/usbdrive/backup/configuration.yaml-01192017-1903’: Permission denied

Does your user have access to /mnt/usbdrive/backup/ ?

well, i dont know,how i can know it?

See below:

@silvrr

ok i put SUDO now it works,

backup_configuration: SUDO cp -a /home/homeassistant/.homeassistant/configuration.yaml “/mnt/usbdrive/backup/configuration.yaml-$(date +”%m%d%Y-%H%M")"

but my pen EMPTY again

The hass users does not have sudo permissions. You can give that user sudo permissions but that comes with certain security risks.

The best bet is giving user homeassistant permissions to write to /mnt/usbdrive/backup/

@silvrr my user is pi… how can write permissions on /mnt/usbdrive/backup?
can you tell me the commands?

your user as far as home assistant is concerned is ‘homeassistant’

See the link I provided above for setting permissions.

thanks, but the problem is the same.
My pen is empty…
very strange. there is something wrong here,

@silvrr ok i solved my problem. if you want add this on your topic.

my problem was the mount usb. i followed this guide.

Ermmm i am getting crazy…

Well, when i put this command on console:

cp -a /home/homeassistant/.homeassistant/configuration.yaml “/media/usb1/backup/configuration.yaml-$(date +”%m%d%Y-%H%M")"

The configuration.yaml is saved on folder.

But when i put the same line on shell…and run it…
The configuration.yaml is not saved…

@silvrr help again please.

Sounds like your Homeassistant users does not have access to the directory on the USB drive. Did you set the permissions for user Pi or Homeassistant?

Which installer did you use? I can point you to the commands to test it in the virtual environment and as user HomeAssistant.

@silvrr i installed my HA from https://home-assistant.io/getting-started/installation-raspberry-pi-image/

but i am still confused about set permissions…i think all is ok…
I use WINscp and i see the folder /media/usb1/backup/.

on putty i should put wihch commands? i have many doubts about permissons bla bla bla.
sorry again for i ask you about this, but its very important for me.

SOLVED.

ok @silvrr i real all with more attention and i can set the permission for homeassistant, now i can see the files on my SDcard.
Thanks again.

Checkout BitBucket.org - it is a GIT system with free private accounts. I use it all the time.

I create a doc on the site regarding backup to usb. With retention and checks if the usb drive is there etc… see https://home-assistant.io/docs/ecosystem/backup/backup_usb/

Created one for drop box too https://home-assistant.io/docs/ecosystem/backup/backup_dropbox/ although not perfect (it syncs all) it works.

2 Likes