Restore a deleted mailbox from backup

Please, who can give some instructions how to restore a backup on a running MaiB server.
I accidently deleted a user account and I would like to now if this mailbox can be restore
if I would restore a system backup.

I read here Restore from a backup some instructions to restore from a backup, but I really don’t understand those instructions.
Maybe because the backup is restore on a new server.

If someone could guide to this on the existing server, you would be great.

Did you delete the files using SSH/SFTP, or just deactivate the account in the control panel?

Hello Josh,

The files were deleted using SSH/FTP indeed.
I deleted the directory /home/user-data/mail/mailboxes/mydomain.nl/userA on the machine.

I wanted to deleted another account, from user B, because user B migrate to another server. But instead to deleted the account of user B, I deleted the account from user A.

I really hope that I still can do some kind of recovery.

Hi,

So, restoring files is a bit difficult. Sorry that this isn’t more polished yet.

Assuming you haven’t changed the backup settings in the control panel, this very long line will help you:

PASSPHRASE=$(cat /home/user-data/backup/secret_key.txt) duplicity restore --time 3D --file-to-restore mail/mailboxes/domain/user file:///home/user-data/backup/encrypted/ /tmp/restored-files

The part --time 3D says how long ago to restore from. 3D means three days ago. You may have to change that part. This should be just before when you deleted the files. A backup is made each night — hopefully the backup from a few days ago is still there. (It should be. Backups are held for a minimum of three days.)

--file-to-restore mail/mailboxes/domain/user says what files to restore. You should change domain and user to match the directory path that you deleted.

The restored files will be placed in /tmp/restored-files. You can then move that whole directory into the right place, like:

mv /tmp/restored-files /home/user-data/mail/mailboxes/domain/user

Let me know how it goes.

Josh,

I follow your instructions and the files from userA were restored. I move them to the right folder. But when login with Roundcube, I can see only the INBOX folder. No Sent and any other folders.

Does this mean that a backup is only made for the INBOX folder or is something else what is missing to see all folder in Roundcube.

Try to solve this one by meself.

First I have move everything in /home/user-data/mail to /home/user-data/mail01, because I don’t want to change nothing for the current users.

Then I ran:
PASSPHRASE=$(cat /home/user-data/backup/secret_key.txt) duplicity restore --time 7D --file-to-restore mail file:///home/user-data/backup/encrypted/ /tmp/restored-files

After that I move all directories/files in /tmp/restored-files to /home/user-data/mail
If passwords of mail account have been change recently, then set these password again.

Now when login to Roundcube I can see all folders off userA.

Hi @pbx_ramdas. I’m glad you were able to figure it out. I’m not sure why the non-inbox folders weren’t restored by the first method. Thanks for reporting back what happened — I’ll look into it.

Hi Josh,

That procediment doesn’t work, the account is empty. Can you see that? I have a client that deleted the content from 2 accounts by mistake.

Shouldn’t be:

mv /tmp/restored-files/* /home/user-data/mail/mailboxes/domain/user/

?

Ok, i have restored the temp files but only the inbox was restored, the others have internal errors.

If you’ve followed the above instructions exactly, using the --file-to-restore flag, then yes, you’d move that folder entirely to its new home, which from your message does look to be correct.

Yes, but only the inbox is working, the others sent, archive, etc are showing internal error. What i’m missing here?

Can you paste the image of that that error looks like? Is it coming from Roundcube itself?

Yes roundcube.

Do you see anything that is helpful when you look into:
/var/log/roundcubemail/errors
file?

There’s nothing there about this account or anything related.

Okay, change into one of the directories causing you the issue. You will find a file called:
dovecot.index
You want to move that index to a different filename so that the indexes regenerate.

mv dovecot.index dovecot.index.bak

Then navigate to that one in Roundcube again and see if it now works. If so, then you can repeat for the other directories. This occurs because dovecot indexes are stale since this was a rebuilt mailbox.

Now even inbox is not working, same internal error.

A new dovecot.index wasn’t generated.

Did you log out of roundcube first and then back in?

Yes, also stop/start services and didn’t work too. Doesn’t regenerate the index