Created new add-on to backup snapshots to Google Drive

hassio-addon
Tags: #<Tag:0x00007f205666cd08>

#42

Here’s how I’ve set mine up. I have it run a scheduled backup and then 30 minutes later, I have it upload to my google drive.

automation:
  - alias: Weekly Backup Friday at 3 AM
    initial_state: 'on'
    trigger:
      platform: time
      at: '3:00:00'
    condition:
    - condition: time
      weekday:
        - fri
    action:
    - service: hassio.snapshot_full
      data_template:
        name: Automated Backup {{ now().strftime('%Y-%m-%d') }}
    - service: notify.sms_notification
      data_template:
        message: Creating backup named "Automated Backup {{ now().strftime('%Y-%m-%d') }}"

  - alias: Weekly Backup to Google Friday at 3:30 AM
    initial_state: 'on'
    trigger:
      platform: time
      at: '3:30:00'
    condition:
    - condition: time
      weekday:
        - fri
    action:
    - service: rest_command.google_backup


Backup as automation with date and hours in name
#43

Thanks weok! Will be giving this ago when I get home later - looks bloody good. So simple to setup (I kept trying to code it as one block of scripts, but that was just stupid!), seems so obvious reading your code!

Update: All working a treat, just had a chance to add the code, tweaked the timings and updated the notify (bloody handy to know whats happening).

  • service: notify.ios_my_iphone

Note: For those wanting to use this code, don’t forget to add the rest_command to your config file (as per the github readme)

rest_command:
  google_backup:
    url: 'http://localhost:8055/gb/doBackup'
    timeout: '300'

Thanks again!!!


#44

Hi @samccauley

really a great addon, thanks!

This is my config

{
  "fromPattern": "/backup/*.tar",
  "backupDirID": "xxxxxxx",
  "purge": {
    "enabled": true,
    "preserve": 5
  },
  "purge_google": {
    "enabled": true,
    "preserve": 5
  }
}

I’m trying to use within Nodered and I’m using a node configured like this, calling an HTTP GET, but as you can see I get a “no response from server”.

BTW, my Nodered server is on a different server than the Home Assistant one, but in the same local network.

Am I doing something wrong?

Thanks


#45

Have you tested calling the service from your desktop browser, or a testing tool like Postman? Does that work?


#46

Yes, it works.

I have found that even if I get that error, the service is called and it’s working.

Thanks


#47

Makes me suspect a bug in Node-RED’s HTTP Request/Response code. I don’t know. I don’t use Node-RED myself.


#48

I tried uploading to Google via the below script but it failed. Any ideas what I have done wrong?

rest_command:
  google_backup:
    url: 'http://localhost:8055/gb/doBackup'
    timeout: '300'
    
script:
  upload_backup_to_google:
    sequence:
      - service: rest_command.google_backup

error log:

Wed Dec 05 2018 16:27:06 GMT+0930 (Australian Central Standard Time)

Error executing service <ServiceCall rest_command.google_backup (c:eb253cc9bd2d4bfeaa9486f10c223964)>
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/rest_command.py”, line 103, in async_service_handler
headers=headers
File “/usr/local/lib/python3.6/site-packages/aiohttp/client.py”, line 391, in _request
await resp.start(conn)
File “/usr/local/lib/python3.6/site-packages/aiohttp/client_reqrep.py”, line 757, in start
message, payload = await self._protocol.read()
File “/usr/local/lib/python3.6/site-packages/aiohttp/streams.py”, line 543, in read
await self._waiter
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/rest_command.py”, line 103, in async_service_handler
headers=headers
File “/usr/local/lib/python3.6/site-packages/async_timeout/init.py”, line 45, in exit
self._do_exit(exc_type)
File “/usr/local/lib/python3.6/site-packages/async_timeout/init.py”, line 92, in _do_exit
raise asyncio.TimeoutError
concurrent.futures._base.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/core.py”, line 1177, in _event_to_service_call
await service_handler.func(service_call)
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/rest_command.py”, line 113, in async_service_handler
_LOGGER.warning(“Timeout call %s.”, request.url)
UnboundLocalError: local variable ‘request’ referenced before assignment


#49

strangely it looks like the upload still worked…


#50

Trying to use it for camera snapshots without success

config:

homeassistant:
  whitelist_external_dirs: 
    - /config/www/

getting this response:

{“backupTimestamp”: “2019-01-07T21:17:14.288088”, “fromPattern”: “/config/www/*.jpg”, “backupDirID”: “1fhtdVlOwzM0Q0mECjxe2kztu9vfA1yWv”, “fileCount”: 0, “alreadyCount”: 0, “backedUpCount”: 0}

folder contains several JPG files but not recognized, any idea?


#51

was wondering can the .tar file created be with password option?


#52

you can give the .tar file a password when you create it in the snapshot creation stage (not part of this add-on). This add-on uploads the snapshot, doesn’t create it


#53

Hey, I have the same error.
Could you please tell me how you managed to make it worked ?


#54

I just started the whole auth process over again from memory


#55

Well thank you, I reinstalled it and it is now working.


#56

Can i get the it to also name the file within google drive the same as within hassio? and also can i add the version number in the name… im using the automation and templates above.

works great so far otherwise


#57

Thanks for sharing your add-on.
I’m wondering Is it possible to have multiple source folder and destination folder with this add-on?
Let’s say I want to backup “/backup/*.tar” and “/config/*.yaml” files, can we do that?


#58

The backup .tar file contains all the .yaml files by default. Why the double backup?


#59

hi @samccauley.
Any news on a i386 support?


#60

Got everything up and running with authorization but when I call this:

http://<YOUR_HASSIO_HOST>:<HOST_PORT>/gb/doBackup

substituting for my ip address and port. It’s been a blank loading page for 20 minutes now. Is that correct and it just takes a while or am I doing something wrong?


#61

Disregard… guess I was being impatient :smile: