ajeetdsouza/zoxide

Feature Request: Automatic Backup and Recovery for db.zo

Opened this issue · 6 comments

I encountered an issue with zoxide where I had to delete db.zo due to a database file corruption error: zoxide: unsupported version (got 0, supports 3).

That will fix the error, but all data are lost, so I have to type all of the file path again.

It would be helpful if zoxide could automatically create backups of db.zo and have a recovery option for corrupted or incompatible database files.

This feature would improve the resilience of the tool and save users from manual intervention in case of database errors.

Thank you for considering this request.

First problem that would need to be addressed is just importing Zoxide's own format (#591).

For PowerShell users, the workaround that I have been using is querying the entire database, converting to an object, formatting the object to a string array to match the format of Z/Autojump, and then writing that to a file. From here, it would be up to the user on how they would want to handle their backups.

@josephwhite Even though we don't have the final format for db.zo, zoxide could still back it up. Maybe make a copy named db.zo.bak. If there's a problem occurred for loading db.zo, zoxide could try to use the backup or just tell user themselves to recovery it. This way, users won't lose their data, and it doesn't depend on a specific data format. What do you think?

I have a temporary workaround of making a copy of db.zo named db.zo.bak every time I call zoxide success, by configure the command z's behavior.

I have a temporary workaround of making a copy of db.zo named db.zo.bak every time I call zoxide success, by configure the command z's behavior.

Hi @hoofcushion can you share your WAR here?

@wswslzp Here's my ~/.bashrc

if test -n $(command -v zoxide); then
 eval "$(zoxide init $(basename $SHELL))"
 function back() {
  local command="$1"
  shift
  "${command}" "$@"
  if [ $? -eq 0 ]; then
   cp "$HOME/.local/share/zoxide/db.zo" "$HOME/.local/share/zoxide/db.zo.bak"
  fi
 }
 alias cd='back z'
 alias cdi='back zi'
fi

And what does WAR means?