Snapshot naming + Filename

Would it be possible to have the snapshot name I choose in some capacity reflect on the actual filename of the snapshot instead of:
70344a3d.tar
Sometimes I need to find something in an old snapshot (backed up to NAS) and the name would make it much simpler.
I know there will be an issue with some characters and white spaces but perhaps that could be resolved somehow.

Came here looking for the same solution. Backup file names should be meaningful, at least with respect to the date made.

Anyway, I wrote a quick script tonight that may help someone else. On my personal server, I’ve done the manual install and haven’t setup the “hass” binary yet, so this script might not be as useful to someone who can specify the backup name via CLI. Nevertheless, here it is:

#!/bin/bash


#
get_file_create_datetime()
{
	# stat -c %w "$1" --format="%Y"
	date -r "$1" +'%Y-%m-%d_%I-%M%P'
}
make_file_backup_name()
{
	local FILENAME=$(get_file_create_datetime "$1")" - Home Assistant Backup.tar"
	echo "$FILENAME"
}
rename_backup()
{
	local DIR=$(dirname "$1")
	local FILENAME=$(make_file_backup_name "$1")
	local FILEPATH="$DIR/$FILENAME"

	if [ "$1" != "$FILEPATH" ] ; then
		mv "$1" "$FILEPATH"
	fi
}
rename_all_backups()
{
	for FILE_PATH in "$1"/*
	do
		rename_backup "$FILE_PATH"
	done
}

rename_all_backups "$HOME/.homeassistant/backups"

Run the script and it will rename all backup files according to their creation date. Of course, you may want to adjust the hard-coded path, date format, or other parts. Feel free to tweak and upgrade.

i dont think it solves original issue that was reported ;/

I have upvoted this. Seems unfortunate that the name attribute is currently being ignored.

strange longstanding bug? For now I can use the creation date on my share to find the most recent version, but using a name and/or date/time as filename would be an improvement over random.tar

1 Like

There is a HACS implementation called Auto Backup. It allows to set a custom name of the generated archive. It allows variables (as every service). Backups are listed in the normal location.

HCAS auto backup

Super bizarre behaviour. Backup location set to connected storage (Synology NAS).

File name in HA is correct. File name on the NAS is not. They are the same file. Deleting the file in HA GUI deletes file “62048360” shown here. And vice versa.

tried this - within HA the fiel name is exactly as set in the integration. but on my NAS the file name is still the random hash. Did I miss something?

Yeah. Voting for this, because guessing the name on it’s date or size is strange. You can have backups for updates of specific addons and so on. We need filenames!

Guys, they don’t put any priority on it. It’s open for many years now.

I don’t beg for things when it’s unlike that anybody will change it. I use a rename command for my backup strategy, it’s just a simple “mv” command on linux host. While waiting for the devs you could use it in your automation.

I’m using HA in Docker. I never checked what OS is used when HA runs native on bare metal. Probably you need do adapt the command or used shell (bin/sh instead of /bin/bash …)

Adapt the path to your need. I placed it in a subfolder /config/docker_files. Name for backup YYYYMMDD_HHMMSS_<name_set_in_script>.tar e.g. 20240817_020103_ha_backup.tar

No support, no warranty. I run script since long time. Test before you use it in your landscape.

Step1: Upload to a folder script

#!/bin/bash
#
backupfolder="/config/backups"
backupname="ha_backup"

cd $backupfolder

find . -not -name "*$backupname*" -type f -print0 | while read -d $'\0' file
do
	mv -n "$file"  "$(date -d @$(stat "$file" -c %X) +"%Y%m%d_%H%M%S")_$backupname.tar"
done

Add script to HA in config.yaml

shell_command:
  rename_habackup: bash ./custom_scripts/renamebackup.sh

Add rename script to your automation or call it using a scheduler.

I’m using HA OS on a RPi and to be honest, this is beyond my ability.
If anybody knows of a way to do this in HA automations it would be greatly appreciated :slight_smile: