ajeetdsouza / zoxide

A smarter cd command. Supports all major shells.
MIT License
20.29k stars 518 forks source link

Feature Request: Automatic Backup and Recovery for db.zo #807

Open hoofcushion opened 2 months ago

hoofcushion commented 2 months ago

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.

josephwhite commented 2 months ago

First problem that would need to be addressed is just importing Zoxide's own format (https://github.com/ajeetdsouza/zoxide/issues/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.

hoofcushion commented 2 months ago

@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?

hoofcushion commented 2 months ago

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.

wswslzp commented 1 month ago

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?

hoofcushion commented 1 month ago

@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?

wswslzp commented 1 month ago

Thanks for your sharing 🙂


发件人: HC @.> 发送时间: 2024年5月15日 22:22 收件人: ajeetdsouza/zoxide @.> 抄送: wswslzp @.>; Mention @.> 主题: Re: [ajeetdsouza/zoxide] Feature Request: Automatic Backup and Recovery for db.zo (Issue #807)

@wswslzphttps://github.com/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

— Reply to this email directly, view it on GitHubhttps://github.com/ajeetdsouza/zoxide/issues/807#issuecomment-2112685539, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHHK5JJC2SZF5EA6K5PQGTLZCNVQ3AVCNFSM6AAAAABHCXVNZCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJSGY4DKNJTHE. You are receiving this because you were mentioned.Message ID: @.***>