Samba Backup: Create and store backups on a Samba share

Hey everyone!

Just wanted to share a Home Assistant add-on with you which allows you to create snapshots and store them on a Samba share. You can check it out here: Samba Backup

There are already similar add-ons available which upload snapshots to Dropbox or Google Drive, but I did not find anything that directly copies to a local NAS. So I created this one.

Main Features:

  • Automatically create snapshots (full or partial) and copy them to a Samba share
  • Cleanup specified number of snapshots locally on the device and on the share
  • Time-based schedules are supported out of the box, advanced triggers can be implemented with a Home Assistant automation
  • A sensor for Home Assistant informs you about status changes and provides you with some statistics

I appreciate any kind of feedback, suggestions or improvements are welcome!

If you like this add-on, please :star2: the Github repo. Thanks.

89 Likes
How to map a NAS network drive?
Hassio snapshots are gigantic
Backup containing media files
Australia - Electrically Certified Hardware
Unable to delete snapshot entry in Web UI after deleting it from CLI
Auto Backup to Synology
Recover backup/snapshot through diskmount
Reducing SD Card crash
Samba Backup Question
Clone SD card
HA stopt working
Backup Files are getting huge
Dropbox backup upload not working anymore?
Automating partial backups
My HA qcow2 vdisk lost partition how can i fix it?
Home assistant full?
Database already huge
Backup stopped working
Last backup sensor for automation
Create disaster-recovery setup
WTH Can't I mount a Remote Share (NAS, SMB, NFS, etc) in HAOS?
Backup Questions
Hasio Snapshot: how to identify given random file names
2023.6 Network Storage Feature - Experiences and Questions
Frustrated with the lack of SSL [Nginx Proxy Manger Solved the issue]
"Sonoff iHost" (smart home hub/computer) from ITead - Can it be hacked to run Home Assistant OS with Bluetooth, Thread/Matter, and ZHA integrations?
SAMBA BACKUP has stopped backing up my installed addons -- SOLVED!
Alternatives to Automatic Backups. Ways to do it yourself
HELP PLEASE - Home Assistant Won't Even Start
Auto-delete backups
BEWARE! If you're using a MicroSD, switch to a HDD NOW!
Off Device Automated Backup
Built In network backup for Snapshots
Fatal error recovery HELP
"Bricked" Pi4 after OTA update tonight - way forward?
šŸ’¾ Create Automated Backups Every Day
Snapshot where is it store
HA Blue Odroid crashed
Hassio not responding
Move from RPi4 4GB > 8GB
Help creating new snapshot via ssh
Home Assistant has stopped working
Backup to NAS not removing deleting files
Is there an addon to copy my snapshots to an NAS?

Nice! This would considerably simplify my off server backup. I’m currently relying on a file sync service running on an always on windows PC to sync backups between Home Assistant and a NAS. And using another custom component to delete old backups.

The only thing holding me back is that your addon only seems to do full backups.

I’ve found I need to exclude some addons to keep the backup small enough to complete in a reasonable time.

Is it possible to do partial snapshots?

Or being able to call the copy and cleanup without creating a backup (I can do the partial snapshot with an automation beforehand).

Yes you’re right. Currently only full backups are possible.

But partial backups can definitely be implemented since they are supported by the Home Assistant CLI which I use to create the snapshots. I’ll see what I can do.

2 Likes

Thank you for this great addon, I love it. I already installed it and it’s working like charm.

A nice addition would be to include an auto-backup scheduler to the addon instead of having it as a separate automation in HA !!!

Already thought about that, but I’m not completely sure yet how a solution should look like.

Maybe it would be a good idea to support a daily backup out of the box. And for everything else one has to create a separate HA automation as this gives way more flexibility when to trigger a backup.

Just an idea (I’m happy with the flexibility of using an automation), you could add a simple schedule to the configuration, e.g. last two options here:

{
  "host": "192.168.178.100",
  "share": "my-share",
  "target_dir": "backups/ha-backups",
  "username": "my-user",
  "password": "my-password",
  "keep_local": "14",
  "keep_remote": "30",
  "backup_password": "my-$tr0nG-pwd",
  "days_to_backup": "mon,tue,wed,thu,fri,sat,sun", # alternatively, 0,1,2,3,4,5,6
  "backup_start_time(s)": "04:20,14:20" 
}
1 Like

Would be a possibility. I’ll probably take a look at that soon.

Meanwhile I released version 1.4 which now supports partial snapshots! :partying_face:
You can specify add-ons and/or folders to be excluded. For the add-ons you have to provide the slugs. In a future release I’ll try to improve that, so that you can also configure it via names instead of the slugs.

Unfortunately, I had to change the role to manager in order to be able to access the installed add-ons. This now results in a bit less security rating.

2 Likes

I’ll give it a go tonight. After I work out what a slug is.

Every Home Assistant add-on has a unique name which they called for whatever reason slug. To my knowledge the slug is somehow created from a hash of the repository name, apart from the official ones. They all start with ā€œcoreā€, e.g. core_ssh.

You can easily find out the slugs by clicking on an installed add-on. The slug is part of the URL.

Thanks. I have the list of slugs already then. As I was using them (without knowing what to call them) in my automation linked above. Actually, looking closer, I have the list of ones I include, but finding the ones I want to exclude will be just as easy now.

This looks very good.
I don’t want to introduce feature creep where it’s not wanted but would you consider an option to copy (some or all of) the config folder as plain files?

My backup routine currently consists of an automation to do a snapshot and then every day when I turn on my Windows PC a scheduled job runs to copy the snapshot to my OneDrive folder along with a plain copy of my config folder. (It also does some housekeeping to delete old snapshots etc but that’s not relevant here).

I can’t tell you how often I have gone to those plain files to quickly restore single .yaml file after an ā€˜improvement’ turned out not to be so!

No big deal if that is outside the scope of what you want to include, I can continue as I am now, but I thought I’d ask.

It all appears to be working.

Just one thing, there were 20 existing snapshots in my backup folders when the samba backup automation ran. Now there are 21. Even though I have keep 20 set for local and remote.

I take it this is because samba backup will only delete it’s own automated backups?

Thanks @thomasmauerer for this great addon.

There is one thing I’d love to see in your addon, customizable snaphot name patterns.
Up to now I used the Google Drive Backup addon which allowed to generate names containing the HA version number. Here is s screenshot:

When it comes to restoring a backup I find it nice to see the HA version and also the type (full / partial) in its name.

It’s the intended behavior to only delete snapshots that were created with this add-on. I search for all snapshots that include ā€œAutomatic Backupā€ in its name, which makes it a bit hard to make the name customizable.

1 Like

Regarding plain files, I would rather say not planned at the moment. I don’t really think it’s a good idea to blow up the configuration possibilities and it would probably complicate the cleanup routines.

What is really the benefit of having plain files? The homeassistant folder, which contains all config yaml files, is included in every snapshot by default. So you just have to extract the tar file in order to get to the plain config files.

1 Like

That’s fine I completely understand.

Speed and convenience :slight_smile:

Yes but it is several levels down. Not a big deal but it is just very convenient to have them at hand for those times when you make a complete mess of something you were trying to improve!

I just released version 2.0 of Samba Backup. This is a breaking release, so please read the following before updating.

  • All snapshots stored on the device will now be cleaned up.
  • Custom names including name patterns {type}, {version} and {date} are now supported. These patterns will automatically be converted to its real values.
  • Out of the box triggers are now supported. If you need an advanced trigger, you can still use a separate Home Assistant automation. But be careful, your existing automations will not work anymore as the syntax has to be different now.
  • Samba Backup is now started as a service running in the background.

All details can be found in the README. If you like this add-on, please give it a star in Github. Thank you :slight_smile:

4 Likes

Can’t thank you enough. This addon has been working perfectly and has considerably simplified my off-server backup scheme.

Is it possible to generate an event in home assistant for successful completion of the backup task so that I can send a notification?

Should be possible, but I don’t know how much effort this means.

We could probably use the mqtt service to publish the current state (Backup started, Backup finished sucessfully, etc.) on a predefined topic. Then you could hook up a mqtt sensor to receive the messages and do whatever you want.

1 Like