Page 1 of 1

Help with Find and Replace

PostPosted: Sun Oct 09, 2016 9:49 pm
by bayon
I'm new to Hazel and trying to figure out the best way to do something. I have a piece of software that does a nightly database dump and we then backup to the cloud. It gives each backup a new name based on the date.

What I need to do is have new backups be renamed to the the same thing, and replacing the oldest backup with the newest. This way, I always have one backup that is the same name, and then my cloud based backup can do a block level backup and only grab what is new.

I have everything setup to rename the files and that is working great, but it's just giving the second backup the added text of "-1" instead of replacing the file. Is it possible to rename and replace within Hazel?

Re: Help with Find and Replace

PostPosted: Tue Oct 11, 2016 10:51 am
by Mr_Noodle
Can you post your rule?

Re: Help with Find and Replace

PostPosted: Tue Oct 11, 2016 4:01 pm
by bayon
Sure, currently the run is very simple.

If extension ends in "mpbak", then rename with pattern "mpbackup.mpbak"

The rename portion is working fine, but as soon as the software creates a new backup, Hazel renames but it becomes mpbackup-1.mpbak.

My goal is to only have one backup at all times with Hazel replacing the oldest backup with the newest one.

Re: Help with Find and Replace

PostPosted: Wed Oct 12, 2016 11:22 am
by Mr_Noodle
The rename action itself doesn't have the option to replace. If the file starts out outside the folder, you can rename it first then do the replacement when you move it into that folder.

Otherwise, you can create rules which check "Date added is/is not among the 1 most recent". Based on that, you can remove a file (if it's not the most recent) or rename it (if it is).

Re: Help with Find and Replace

PostPosted: Wed Oct 12, 2016 7:49 pm
by bayon
This backup is created in this folder by the application, but I do have control of what folder it goes to. If the rename action itself doesn't have replace capabilities, is there any other way in Hazel to automate and replace and existing file? Not all the actions need to happen in one folder, but the end result needs to be the latest backup replacing the older backup, while always retaining the same name.

Re: Help with Find and Replace

PostPosted: Thu Oct 13, 2016 10:56 am
by Mr_Noodle
As mentioned, if you use the move action, it can replace. So if you have the program save to a different folder, you can do the rename first, then move. If you set the move to replace, it should replace the existing file.

Re: Help with Find and Replace

PostPosted: Thu Oct 13, 2016 10:59 am
by bayon
Perfect, I think that will solve my issue. I will give it a shot and report back if I have any issues.

Re: Help with Find and Replace

PostPosted: Fri Oct 21, 2016 1:32 am
by bayon
I've had a new issue come in this process, wanted to bounce it off the board before proceeding. The rename and move rule is working great, but the timing is causing issues. When the software creates the backup, it creates a temporary file and then fills it up with data until the backup finishes. Since my rule is based on an extension ending in .mpbak, as soon as the temp file is created, Hazel soon renames it and moves it before the backup even finishes, corrupting the backup.

I'm guessing there are multiple ways to solve this, but looking for the best one. I figured I could tell Hazel to run at a specific time, well after the backup starts, but I could see this breaking in the future as the backup grows and the backup takes longer.

When the backup starts, it gives me a filename like "MPBackup.tmp.2E8AB3DE-97DB-45D1-9B88-2B1D8D9F7F99.mpbak," then once it finishes it will rename the file to something like "Dentis-2016.06.11-7.0.4-3390.mpbak." I'm thinking I could add the rule <name does not contain "tmp"> since that text will disappear once the backup is complete.

If that is the best way to do it, under the rule would I choose "name does not contain" or "full name does not contain?" Any other foolproof methods I should be considering?

Re: Help with Find and Replace

PostPosted: Fri Oct 21, 2016 10:30 am
by Mr_Noodle
That would probably be the best way. Either name or full name should work here though full name may be slightly better. You can also tighten it up more if you want by using "matches" if you want to be very specific about matching those tmp files.

Re: Help with Find and Replace

PostPosted: Fri Oct 21, 2016 10:33 am
by bayon
Can you explain further how the matches feature works?

Re: Help with Find and Replace

PostPosted: Fri Oct 21, 2016 10:35 am
by Mr_Noodle
Search the help as it's too long to have me re-type here.

Re: Help with Find and Replace

PostPosted: Fri Oct 21, 2016 10:35 am
by bayon
Will do, thank you!