Delete old backups shell command error

Still not deleting old files.

This works fine via ssh: find /backup/* -mtime +30 -exec rm {} +

But trying to run it as a shell command:

delete_old_snapshots: find /backup/* -mtime +30 -exec rm {} +

fails with

2018-09-26 01:15:11 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: find /backup/* -mtime +30 -exec rm {} +, return code: 1
NoneType: None

I can only assume it is some sort of permissions thing.

My hassio build is down atm as Iā€™m moving over to a small desktop ubuntu machine so I canā€™t test it. There must be a way to add the permissions needed by rm, but I donā€™t know them :frowning:

I think I worked it outā€¦
See this thread:

Thanks David. Iā€™ll give this a go.

delete_old_snapshots: find /usr/share/hassio/backup/* -mtime +30 -exec rm {} +

Might have to wait a couple of days for confirmation. I deleted the old files via ssh.

No luck unfortunately.

Error running command: `find /usr/share/hassio/backup/* -mtime +30 -exec rm {} +`, return code: 1

NoneType: None

run
which find
and give the full path for find. in my case it would be
/usr/bin/find /backup/* -mtime +30 -execdir rm {} +

The trouble with that is SSH might work in a different container to HA, as evidenced by the previous commands working via SSH but not as shell_commands.

but the ā€œfindā€ command should be installed in the same directory regardless. There shouldnā€™t be two of them on the same server. What Iā€™m thinking is that ā€œfindā€ isnā€™t being found in whatever environment you have when your shell command is run. You may have said this earlier, is this being run as a cron job or some other scheduler.

A time triggered automation calls the shell command.

core-ssh:~# which find
/usr/bin/find

so try putting /usr/bin in front of your find command and see if specifying the path to find helps.

Sigh.

Error running command: /usr/bin/find /usr/share/hassio/backup/* -mtime +30 -exec rm {} +, return code: 1

One last thing to try:

/usr/bin/find /backup/* -mtime +30 -exec rm {} +

Error running command: `/usr/bin/find /backup/* -mtime +30 -exec rm {} +`, return code: 1

NoneType: None

Thatā€™s it. Iā€™m out of ideas. Going to delete them from the samba share using task scheduler on another always on PC on the network.

Which is the approach Iā€™m using. I think the issue as I said is the docker container running the command_line in yaml is different to the ssh container and those files just arenā€™t available in the command_line container.

@DavidFW1960 do you just have a batch file with the command you posted above called by windows task scheduler?

Not a batch file. Using Task Scheduler defining an action like this:

1 Like

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.
1 Like

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