LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Backup and restore Kmail (https://www.linuxquestions.org/questions/linux-newbie-8/backup-and-restore-kmail-340485/)

RaiReg 07-06-2005 03:10 AM

Backup and restore Kmail
 
Backup and restore Kmail from Mandrake 9.2 to SuSE 9.3

Now I've been using GNU/Linux for several years now but I am no expert and still pretty much a newbie, so I though this would be useful to someone who tried something similar.

Background of the story is that after using Mandrake 9.2 for over a year or so I wanted to switch to SuSE 9.3, but since I am not the only user I had to backup all the data for every user and one of it was all the emails in Kmail. Thing is Kmail doesn't provide a feature to backup or export all the emails but only for the address book (address book can be exported as CSV file and later imported just as easy).

I've been Googling around and the best I could find out was to backup the whole Kmail - Mail directory including sub directories and restore it later after the installation was done. Simple enough I though since in Mandrake 9.2 all the email a user has are stored in :

/home/user/mail/

So I packed everything into mail.tar.gz done. :)

Next I installed SuSE 9.3 and after all configuration was done, I started to restore all the data for each user. After configuring Kmail for the 1st user I thought all I need is to restore the emails to /home/user/mail/ and the job is done but no the directory was not there. :confused:

Now I don't know if the directory structure is different because of the distro or because of the different Kmail version (in Mandrake 9.2 it was an older one). Anyway turns out that the mail is stored in :

/home/user/.kde/share/apps/kmail/mail/

... :rolleyes: ... hidden directory that of course doesn't show in GUI file manager

So what to do :confused:

First of all the directories that I needed to restore were inbox and sent-mail, nothing else. So I created a temporary folder in home directory naming it transfer and then using konqueror file manager restored only files in /home/user/mail/inbox/cur/ directory.

Next I jumped to console logged in as root and run mc (midnight commander), in mc left panel I browsed to /home/user/transfer/ directory and then with the right panel browsed to /home/user/.kde/share/apps/kmail/mail/inbox/cur/ then back to left panel selecting all of the files in it and then copying it to the right panel and wham all of the inbox was restored. Of course I open Kmail to verify this and it was there :D

After deleting all files in /home/user/transfer/ directory I repeated the same thing for the files in /home/user/mail/sent-mail/cur/ and copied all the files to /home/user/.kde/share/apps/kmail/mail/sent-mail/cur/.

Of course I had to repeat this steps for every user but since it achieved the goal it it didn't really matter.

I don't know if this would be done the same way in another distro because I guess there is always a possibility of a different directory structure but it should be more or less the same.

I'm also sure that there must be a simpler/shorter way to do this so if anyone knows it please share it with the rest of us. Perhaps the restoring part can be done by directly sending files to the /home/user/.kde/share/apps/kmail/mail/ if so maybe someone could share how to do that with newbies in mind :)

For anyone who found this useful please drop a note or comment here. :)

archtoad6 09-09-2005 04:41 PM

Simpler way
 
Execute the following code blocks in root terminals: KMenu | System | Terminal Program - Super User Mode

1) On the old box, create the .tar:
Code:

USERS=`ls -l /home/ | grep ^d |awk '{print $9}'`
for U in $USERS ; do tar -rvvf mail.tar /home/$U/Mail/*; done

Feel free to change the 'tar' options & filename.

2) Transfer the .tar to the new box. (Your choice of method.)

3) On the new box, untar
Code:

tar -xf mail.tar
I can't check this w/o risking trashing my system

4) On the new box, change the directory names:
Code:

USERS=`ls -l /home/ | grep ^d |awk '{print $9}'` 
OLD="Mail"
NEW=".kde/share/apps/kmail/mail/"
for U in $USERS;     
do mkdir -p /home/$U/$NEW;
cp -r /home/$U/$OLD/* /home/$U/$NEW;
done

This one, probably the most important, I tested thoroughly on 2 test acct. YMMV.


All times are GMT -5. The time now is 01:59 AM.