Just as well I tested this first. Going to have to map the samba share to a drive.
C:\Users\Tom>ForFiles /p "\\hassio\backup" /s /d -30 /c "cmd /c del @file"
ERROR: UNC paths (\\machine\share) are not supported.
Just as well I tested this first. Going to have to map the samba share to a drive.
C:\Users\Tom>ForFiles /p "\\hassio\backup" /s /d -30 /c "cmd /c del @file"
ERROR: UNC paths (\\machine\share) are not supported.
yeah it took me a few dry runs and google to get it right.
I still cant. I mapped H: to \hassio\backup and set this tast to run at 01:15 with highest privileges:
C:\Users\Tom>ForFiles /p "H:\" /s /d -30 /c "cmd /c del @file"
But the backup are still not being deleted.
I created a batch file and run it nightly as a scheduled task. Below is the contents of the batch file. I use pushd and popd to avoid having to map a drive letter. To avoid having the DOS box appear when the scheduled job runs be sure and select “Run whether user is logged on or not” on the General tab when you setup the scheduled task.
@echo off
pushd \\hassio\backup
forfiles /M *.tar /D -15 /C "cmd /c del @file"
popd
So I haven’t found a fix for the shell command, but I have adapted what the dropbox addon was doing and created a custom service to perform the clean up. In a few days I will provide a link to the code. I need to clean up the services as there is a few hard coded items that should be configurable.
I got some time and cleaned up the code today. The automation hasn’t ran yet, but I have manually called the service several times. Credit for majority of the code goes to the dropbox sync and @danielwelch .
I don’t understand what they mean host and token in configuration.yaml. what needs to be written there?
Host would be the url to your homeassistant (e.g.: http://hassio.local:8123/ it should include the port.) The token is a long lived access token.To create a long lived access token you would need to go to your account profile and click create token in the “Long-Lived Access Tokens” section of the page. I apologize for not providing those in the examples.
I have also since confirmed the automation is working. It’s been running on my setup for the past week without issues thus far.
Thank you for this! Works like a bomb!
looks really promising!
I have no idea what i am doing wrong… but it keeps giving me this error:
Component not found: clean_up_backups_service
I have downloaded the “raw” data into a notepad++ file and saved it as a .py file
I have put the clean_up_backups_service.py file in the root of the custom_component directory
I have multiple custom components and they are working fine
I have put the needed data into configuration.yaml:
clean_up_backups_service:
host: !secret http_base_url
token: !secret clean_up_token
number_of_backups_to_keep: 7
Can someone point me into the right direction?
Thank you!
Hmm. After updating to 0.91.0 the following automation is failing:
automations.yaml
- id: daily_snapshot_clean_up
alias: Daily Snapshot Clean Up
trigger:
platform: time
at: '04:00:00'
action:
- service: clean_up_backups_service.clean_up
configuration.yaml:
clean_up_backups_service:
host: !secret clean_up_base_url
token: !secret clean_up_token
number_of_backups_to_keep: 20
With the following error in the log:
2019-04-06 04:00:05 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.daily_snapshot_clean_up. Unknown error for call_service at pos 1:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 57, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/local/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 839, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 301, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 168, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x6cd1dc10>: Failed to establish a new connection: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='[REDACTED].duckdns.org', port=443): Max retries exceeded with url: /api/hassio/snapshots (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x6cd1dc10>: Failed to establish a new connection: [Errno -3] Try again'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/homeassistant/components/automation/__init__.py", line 380, in action
await script_obj.async_run(variables, context)
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py", line 131, in async_run
await self._handle_action(action, variables, context)
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py", line 210, in _handle_action
action, variables, context)
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py", line 299, in _async_call_service
context=context
File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 88, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context)
File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1138, in async_call
self._execute_service(handler, service_call))
File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1162, in _execute_service
await self._hass.async_add_executor_job(handler.func, service_call)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/clean_up_backups_service.py", line 66, in handle_clean_up
snapshots = get_snapshots()
File "/config/custom_components/clean_up_backups_service.py", line 38, in get_snapshots
snapshot_info = requests.get(hassio_url + "snapshots", headers=headers)
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='[REDACTED].duckdns.org', port=443): Max retries exceeded with url: /api/hassio/snapshots (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x6cd1dc10>: Failed to establish a new connection: [Errno -3] Try again'))
The funny thing is if I trigger the automation manually (using the trigger option in the automation’s more info card) it works as expected (it deletes all but 20 snapshots).
I was planning on upgrading this weekend. I’ll take a look as soon as I upgrade and fix the code.
So I’m a little confused at the moment. I adjusted my trigger time on my automation and made sure it would delete at least one backup. Upon it’s execution I received no errors and it completed deleting the backup. Are you on .91 or .91.1? I upgraded to .91 to try
Also which version of hassos are you on I am on 1.12. You can see this by going to the hassio view and clicking on system.
I’m on HassOS 2.11 and HA v0.91.0.
I have changed nothing related to this (added a couple of cameras and restarted a few times) and it is working again.
EDIT: Failed again last night. Same error.
socket.gaierror: [Errno -3]
seems to mean DNS resolution failure.
I’m using my DuckDNS address. I would try with the local one instead. But I have no certificate for https://10.1.1.100:8123 only the DuckDNS domain so I’m not sure if that will help.
Sorry for my delay in responding, I am not getting an error. I am looking into it tonight I’ll keep this thread updated as I have them.
Of course last night it all worked and no errors again. (facepalm). I’m scanning the logs now to find the error I saw a few days ago.
Quick update before we wait till my automation executes. I found a few things:
Hopefully it will fail tonight and I can get some information. I have updated to the same hassos version as you as well. Thank you for your patience.