Hass.io Add-on: Upload hassio snapshots to Dropbox

Hey guys,
So I’m using Hassio with the addon. I have it all working - snapshots being automated, and then uploading to dropbox.

However, I am having the automation name the snapshot with the date, etc. However, the backups being uploaded to dropbox still only have the alphanumeric filename.

Any ideas why it does this?

Because that’s what it does. That is the filename. The friendly name is stored internally in the rar file. Hass.io requires the 8 digit rar name and when you refresh the snapshot list it reads the friendly name and displays it.

1 Like

Great stuff guys! Pretty new to hassio as well as the OS’s, HW platforms, and IoT in general, but have really enjoyed the challenges offered by learning new skills. I love Daniel’s add-on, and I have managed to automate my backups as well as the upload to Dropbox. There is something that I have been wondering. What is the best way to automatically determine when a snapshot completes (or alternatively if a snapshot completed). I am assuming it is a challenge as people more experienced than me seem to be putting arbitrary time gaps (30 min, 1 hour, 2 hours) between the snapshot and the upload to dropbox based on how long they expect the snapshot to actually take. Is there no way to initiate the snapshot and then have the upload take place based on the completion of the snapshot process?

If there isn’t a state or something that can be queried, or can we watch the list of local backups for our newly minted one to show up? Can I assume that if the automation is no longer “on” that the snapshot has completed (I assume not)?

This is my log file based on auto-launching the snapshot from an automation (my automation follows). My install is still very small and the snapshots only take a few minutes to complete when manually executed via the GUI.

2018-08-30 23:00:00 INFO (MainThread) [homeassistant.components.automation] Executing Daily Backup at 11 PM
2018-08-30 23:00:00 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: name=Daily Backup at 11 PM, message=has been triggered, domain=automation, entity_id=automation.daily_backup_at_11_pm>
2018-08-30 23:00:00 INFO (MainThread) [homeassistant.helpers.script] Script Daily Backup at 11 PM: Running script
2018-08-30 23:00:00 INFO (MainThread) [homeassistant.helpers.script] Script Daily Backup at 11 PM: Executing step call service
2018-08-30 23:00:00 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=hassio, service=snapshot_full, service_data=name=Automated Backup 2018-08-30>
2018-08-30 23:00:10 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.daily_backup_at_11_pm, old_state=<state automation.daily_backup_at_11_pm=on; last_triggered=2018-08-30T16:28:30.077489-04:00, id=daily_backup_and_cleaning, friendly_name=Daily Backup at 11 PM @ 2018-08-30T16:27:59.728052-04:00>, new_state=<state automation.daily_backup_at_11_pm=on; last_triggered=2018-08-30T23:00:10.633672-04:00, id=daily_backup_and_cleaning, friendly_name=Daily Backup at 11 PM @ 2018-08-30T16:27:59.728052-04:00>>
2018-08-30 23:00:10 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1914816624: Sending {‘id’: 2, ‘type’: ‘event’, ‘event’: {‘event_type’: ‘state_changed’, ‘data’: {‘entity_id’: ‘automation.daily_backup_at_11_pm’, ‘old_state’: <state automation.daily_backup_at_11_pm=on; last_triggered=2018-08-30T16:28:30.077489-04:00, id=daily_backup_and_cleaning, friendly_name=Daily Backup at 11 PM @ 2018-08-30T16:27:59.728052-04:00>, ‘new_state’: <state automation.daily_backup_at_11_pm=on; last_triggered=2018-08-30T23:00:10.633672-04:00, id=daily_backup_and_cleaning, friendly_name=Daily Backup at 11 PM @ 2018-08-30T16:27:59.728052-04:00>}, ‘origin’: ‘LOCAL’, ‘time_fired’: datetime.datetime(2018, 8, 31, 3, 0, 10, 634646, tzinfo=), ‘context’: {‘id’: ‘12cd39f866ba4d3c8da64eab44e678c8’, ‘user_id’: None}}}
2018-08-30 23:00:10 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1911756848: Sending {‘id’: 2, ‘type’: ‘event’, ‘event’: {‘event_type’: ‘state_changed’, ‘data’: {‘entity_id’: ‘automation.daily_backup_at_11_pm’, ‘old_state’: <state automation.daily_backup_at_11_pm=on; last_triggered=2018-08-30T16:28:30.077489-04:00, id=daily_backup_and_cleaning, friendly_name=Daily Backup at 11 PM @ 2018-08-30T16:27:59.728052-04:00>, ‘new_state’: <state automation.daily_backup_at_11_pm=on; last_triggered=2018-08-30T23:00:10.633672-04:00, id=daily_backup_and_cleaning, friendly_name=Daily Backup at 11 PM @ 2018-08-30T16:27:59.728052-04:00>}, ‘origin’: ‘LOCAL’, ‘time_fired’: datetime.datetime(2018, 8, 31, 3, 0, 10, 634646, tzinfo=), ‘context’: {‘id’: ‘12cd39f866ba4d3c8da64eab44e678c8’, ‘user_id’: None}}}

Automations.yaml:

id: daily_backup_and_cleaning
alias: Daily Backup at 11 PM
trigger:
platform: time
at: ‘23:00:00’
action:
service: hassio.snapshot_full
data_template:
name: Automated Backup {{ now().strftime(’%Y-%m-%d’) }}

1 Like

Hi freekey,

This looks exactly what I’m looking for, it is easy to miss the fact that a successful notification didn’t turn up.

Can you please share the iftt setup?

Hey All,

Any ideas why it won’t let me put the date first in the snapshot name? eg.

name: {{ now().strftime('%y-%m-%d') }} - Automated Backup

its throwing an error:

sequence entries are not allowed here

If I remove the space between the ‘-’ and ‘Automated’ I get this error:

expected <block end>, but found ‘<scalar>’

Just a personal thing, I like to label files yymmdd - description
Any insight would be greatly appreciated.

Loving this add-on though thanks Daniel. +1 vote for google drive also

Hi LintHart,
I can’t tell you “why” but I can tell you that if you put quotes around it it will work:

    name: "{{ now().strftime('%Y-%m-%d') }} Automated Backup"

If you have the text first it will work with or without the quotes:

    name: "Automated Backup {{ now().strftime('%Y-%m-%d') }}"
    or
    name: Automated Backup {{ now().strftime('%Y-%m-%d') }}

@ShampainTstBeerBdgt Perfect thanks mate. Worked like a charm

1 Like

the addon works perfectly. I have a problem since the file in the backup directory is more then 1GB and my space in dropbox is limited. I think most of the space is the history, which I do not care (much) to be backedup

Not sure how this file in the backup folder is created and if it is possible to reduce the files, or eventually have this addon reduce the size in some way …??

1 Like

I use the delay between trigger and upload as you have said but just use the ifttt applet that watches Dropbox for new files appearing in a specific folder to send a trigger to run a script that pops a persistent notification up in the front end. Don’t really care what stage a backup is at, just that it has completed and been uploaded.

Hey @Pterry - glad it’s of use! Sure - see below, let me know if you have any questions!

Set up a new applet with Dropbox as the IF and Webhooks channel as the THEN THAT.

Then configure as follows:

Dropbox: “New file in your folder” trigger.

Subfolder name: I leave this blank as I put the backups in my main Dropbox as this is all I use Dropbox for (so the files are not in a folder) but you can specify a folder here to look at if you want to

—————
 
WEBHOOKS: “Make a web request” action

URL: https://yourdomain.duckdns.org/api/services/input_boolean/turn_on?api_password=PASSWORD

Method: POST

Content type: application/json 

Body: {"entity_id":"input_boolean.dropbox_sync_completed"}

Thanks freekeys!

That was a great help as I hadn’t used IFTTT before. I have it set up and running although in the short term I have gone for the script task sending a message on success or failure until I’m more confident of the system.

  check_dropbox_successful:
    sequence:
      service: notify.telegram
      data_template:
        title: 'Home Assistant'
        message: >
            {% if is_state("input_boolean.dropbox_sync_completed", "off")  -%} 
              Dropbox backup was not successful 
            {%- else -%}  
              Dropbox got a new file! 
            {%- endif %}

Nice! Pleased it worked out :+1:

My question hasn’t had a lot of traction so I looked into it further on my end and found the following in the system log when the snapshot starts:

18-09-08 05:13:05 INFO (MainThread) [hassio.snapshots] Full-Snapshot cc9c9866 start

and the following when it ends:

18-09-08 05:14:43 INFO (MainThread) [hassio.snapshots] Full-Snapshot cc9c9866 done

system_log_after_snapshot.yaml (3.0 KB)

as well as multiple system log entries in between those lines for the various steps being initiated and completed (see attached text file). Is there a way to use the system log to verify that the snapshot completed (Full-Snapshot <snapshot_name> done)? Ideally within an automation?

Is this of no interest to anyone or am I committing some kind of beginner crime like not starting a new thread or something?

google drive would be nice too! actually better for google fanatics like me - i never use Dropbox. i know ur dropbox addon is stable and that you started a long time ago working on Google drive but i guess development stopped? btw for oauth might be better to use Google application specific password: https://support.google.com/accounts/answer/185833?hl=en

Hi Daniel… 0.79 seems to have broken keep last functionality. I see someone has opened an issue on Github and I posted there as well.

Log shows:

{"command": "upload"}
[Info] Received message with command upload
[Info] Uploading all .tar files in /backup (skipping those already in Dropbox)
 > Skipping already existing file "/home-assistant-backups/26065462.tar"
 > Uploading "/backup/725e826b.tar" to "/home-assistant-backups/725e826b.tar"... DONE
 > Skipping already existing file "/home-assistant-backups/773aab24.tar"
 > Skipping already existing file "/home-assistant-backups/91c1f4a0.tar"
 > Skipping already existing file "/home-assistant-backups/a41d76e7.tar"
 > Skipping already existing file "/home-assistant-backups/c7d07f53.tar"
[Info] keep_last option is set, cleaning up files...
Traceback (most recent call last):
  File "/keep_last.py", line 47, in <module>
    main(args.number)
  File "/keep_last.py", line 15, in main
    snapshot_info.raise_for_status()
  File "/usr/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: http://hassio/snapshots

As per github it seems there is a missing line setting a manager role in config.json
As I’m running Hassio on Debian I can edit this file myself…

/usr/share/hassio/addons/git/7be23ff5/dropbox-sync/config.json

{
  "name": "Dropbox Sync",
  "version": "1.2.0",
  "slug": "dropbox_sync",
  "description": "Upload your Hass.io backups to Dropbox",
  "url": "https://github.com/danielwelch/hassio-dropbox-sync",
  "startup": "before",
  "stdin": true,
  "hassio_api": true,
  "hassio_role": "manager",
  "boot": "auto",
  "map": ["backup", "share"],
  "options": {
    "oauth_access_token": "<YOUR_ACCESS_TOKEN>",
    "output": ""
  },
  "schema": {
    "oauth_access_token": "str",
    "output": "str",
    "keep_last": "int(0,)?",
    "filetypes": "str?"
  },
  "image": "dwelch2101/dropbox-sync-{arch}"
}

Of course if I restart the addon it might get wiped out and I’ll need to readd it. Hopefully Daniel will fix it soon. I just triggered my automation so I’ll know soon if it works again now.

Hi @danielwelch Great Addon ! :slight_smile:

Is there a way to always upload the file to dropbox with the same name? the idea was to use dropbox versioning and thus save space on dropbox wich get full quite fast.

This way we could have just one file named ‘HassBackup.tar’ and be able to restore old versions within the dropbox itself. Just like in the example below:

drop1
drop2

1 Like

1.3.0 fixed uploading to dropbox. Thanks!

1 Like

Love this add-on!

When I use the !secret directive to store my token in secrets.yaml I get the following error when the script is trying to execute:

Error loading data from /etc/uploader.conf...
It is recommended to run ./dropbox_uploader.sh unlink

If I put the access token directly in the configuration it seems to work. Any idea what’s going on?

This commit seems to imply that all that needs to be done is allowing the add-on to access the config directory, which should be a quick fix for me to implement.

No it’s not, that fix is actually only for add-ons based on the community add-ons base image by @frenck. That image has a lot of built-in functions (like logs, banners, support for secrets…) https://github.com/hassio-addons/addon-base