MUCH LATER EDIT: I just got a like on this post, 8 months after I originally posted it so in case anyone else comes by here and is interested, there is another forum post where I include a much better version of the .cmd
file.*
Look here → [I give up, just is not worth the time and effort - #122 by sparkydave]
EDIT:
If anyone is interested I decided to add the following to my .cmd
file so that only files newer than 14 days are kept. (PLEASE CHECK YOUR PATH BEFORE USING!!!)
forfiles /P "D:\Users\[user_account_name]\OneDrive\Home Assistant Snapshots" /D -14 /C "cmd /c del @file"
Is there a way to automatically delete old snapshots on my Pi from within HA?
If anyone else like me doesn’t use Dropbox or GitHub but does use OneDrive (i.e. every Windows user who signs on to their PC with a Microsoft account) then another solution is as follows. It’s not as slick as the other solutions but once setup it is automatic. And I’m not claiming to have been clever here, what I use isn’t rocket science but it might hep anyone who hasn’t considered it.
I have an automation that does a nightly snapshot:
#==================================
#== Create a daily snapshot backup
#==================================
- alias: Daily snapshot
trigger:
platform: time
at: '3:15:00'
# No need for backup if on holiday as nothing will have changed
condition:
condition: state
entity_id: input_boolean.holiday_mode
state: 'off'
action:
service: hassio.snapshot_full
data_template:
name: automated backup {{ now().strftime('%Y-%m-%d') }}
On my PC which I log in to every day I have a .cmd
file that does a Robocopy to OneDrive
@echo off
REM
REM --- Copy Home Assistant Snapshots to OneDrive
REM
echo ====================================================================
echo COPYING - Home Assistant Snapshots
echo ====================================================================
robocopy "\\[ip address of HA Pi]\backup" "D:\Users\[user_account_name]\OneDrive\Home Assistant Snapshots"
pause
Robocopy is included in all versions of Windows since (I think 8). The pause is unnecessary but gives a chance to see that it has run correctly.
I then set up a scheduled job to run the .cmd
file every time I log on to my Windows PC. (Search for Task Scheduler on your PC).
I have also set the folder to be available on and off line.
This way I have a snapshot every day on my Pi, on my PC and in the cloud.
I hope this is useful.