Script to backup Maildir emails within home areas
Hi
I'm looking for a bash shell, php or perl script to backup all /home/username/Maildir directories (and there content) within the /home/ directory to another folder location such as /backup/username/Maildir. This will enable me to backup emails within my postfix mail server environment. I've already got an idea of what the program should do and I'm assuming to somebody in the know that it would be easy. -It needs read the contents of the /home dir to find all the directories that contain a Maildir directory -then somehow stick all these into an array or something -then in a loop feed in all the values and run a cp command on top level directory (/home/username) and then a cp on the Maildir directory (and all its contents). Obviously this would have to contain the mkdir command to generate the new folders in the location its backing up to. -And when all are copied, come out of the loop and end the script I've never really done any scripting and don't have a scooby doo where to start but with my basic knowledge of programming, I have a rough idea of what is needed. So if anybody could point me in the direction of some good resources, get me started or even better, just write it for me - that would be absolutely fantastic! Seriously though, any help would be much appreciated. Thanks |
I love Linux, if only for the fact that there are always a million ways to do anything.
If you want to use a loop to process each home directory, then you could do something like this:- Code:
cd /home There are, as I suggested, other ways. |
Quote:
|
As Stephane suggests, find will work as well. Like I said there are always many ways to do one thing.
Code:
cd /home |
Hi chaps, thanks for the replies.
I assume this is some none specific kind of script so I just stick it in a file and run it like so #./filename ? Excuse my lack of experience :) |
Yes, but you also need to set the execution permissions with "chmod 755 filename". When you do "ls -l filename" you need to see "x" in the permission list - e.g. rwxr-xr-x
|
Hi blacky, I've tried running this today but its having troubling copying the directory structure as the same folder doesnt exist in the location its backing up to.
I get the following output: #./backupscript cp: cannot stat '/backup/dave/': No such file or directory cp: cannot stat '/backup/guy/': No such file or directory cp: cannot stat '/backup/john/': No such file or directory # I tried fixing this with the adding some mkdir's to the loop but there are many files and it still did something wrong. Is there a workaround for this? |
If you're using the "for" loop approach, try modifying like this:-
Code:
cd /home |
All times are GMT -5. The time now is 09:53 AM. |