qmail backup zip method

I'm using qmail.
I forward all emails from email@xxx.com to email2@xxx.com to make email2@xxx.com my backup accounts.

I have the below commands to Zip up all qmail backup files.

cd
cd /xvmailhome/domains/MyDomain.com
tar cvf /backup/MyDomain.gz *2                'This command tars only those accounts ending with 2
rm -rf ./*2

I realised this sometimes creates very huge files which are difficult to unzip.
How can I modify it so it goes into every single email account ending with 2 and creates a single .gz file for Each Email Account ending with 2.

tar cvf /backup/MyDomain/EmailAccount2.gz *2    

Take note I might repeat the process for different domains.
LVL 1
dennisdominicAsked:
Who is Participating?
 
omarfaridCommented:
Hi,

Ok, that is what the script should do, but for some reason you are getting error message.

The next step is to

cd /xvmailhome/domains/MyDomain.com # where the directories are

we want to test backing up of of those directories manually

e.g. run

tar czf /backup/mydir/emailA2.tar.gz  emailA2 # this should create a zipped tar file for emailA2 in /backup/mydir
0
 
omarfaridCommented:
Hi,

Since you are not going to tar then zip the files, then you can copy each file into a dir, zip and zip the copy:

mkdir /mydir (make sure that  you have enough space)
cd /xvmailhome/domains/MyDomain.com
for file in *2
do
    cp $file /mydir/$file
    gzip /mydir/$file
done

You may then do whatever you want with the zipped files (like backup on tape, etc.).

If you intend to keep the zipped files on-line then you may create a separate dir for each domain and repeat the above by replacing /mydir with each domain dir.

0
 
http:// thevpn.guruCommented:
cd
cd /xvmailhome/domains/MyDomain.com
ls *.2 | tar cvf
rm -rf ./*2

try this
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
ravenplCommented:
First will not work for folders with whitespaces (common problem)
The second will not work at all (or I don't know how to use tar).

ls -1 *2 | while read f; do
 tar czf "/backup/MyDomain_$f.tar.gz" "$f"
done
0
 
dennisdominicAuthor Commented:
omarfarid's method gave me this...

cp: omitting directory `a2'
gzip: /backup/a2: No such file or directory
cp: omitting directory `b2'
gzip: /backup/b2: No such file or directory
cp: omitting directory `c2'
gzip: /backup/c2: No such file or directory
cp: omitting directory `c2'
0
 
dennisdominicAuthor Commented:
ravenpl's method..  I think it's almost there..


/backup/dlim/MyDomain_achong2: Unknown host
tar: /backup/dlim/MyDomain_a2\:.tar.gz: Cannot open: Input/output error
tar: Error is not recoverable: exiting now
tar: Maildir: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
tar: : Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
/backup/dlim/MyDomain_b2: Unknown host
tar: /backup/dlim/MyDomain_b2\:.tar.gz: Cannot open: Input/output error
tar: Error is not recoverable: exiting now
tar: Maildir: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
0
 
ravenplCommented:
Can You give here whole script? And "ls -1 2*" output?
> /backup/dlim/MyDomain_achong2: Unknown host
That's really strange - unknown host...
> /backup/dlim/MyDomain_a2\:.tar.gz
even stranger, where from that "\:" came from?
> Cannot open: Input/output error
You sure it's accessible?
0
 
omarfaridCommented:
Hi,

The error is because it is a directory. Here a modified one:

mkdir /mydir (make sure that  you have enough space)
cd /xvmailhome/domains/MyDomain.com

for dir  in *2
do
    tar czf /mydir/$dir.tar.gz  $dir
done
0
 
dennisdominicAuthor Commented:
omoarfarid method


tar (child): /backup/mydir/a2.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
Broken pipe
tar (child): /backup/mydir/b2.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
Broken pipe
0
 
omarfaridCommented:
Hi,

What is the perms on the /backup and /backup/mydir ?

Can you run the following on your  system and let us see what you will get:

tar czf /backup/mydir/etc.tar /etc

The above command will create a compressed tar file (etc.tar) in /backup/mydir for /etc dir.

0
 
dennisdominicAuthor Commented:
[root@ns /]# tar czf /backup/dlim/etc.tar /etc
tar: Removing leading `/' from member names

Maybe I should rephrase my question again.
I'm running qmail, and all the email accounts are forwarded to *2 as backup.. so emailA will have a copy on emailA2, emailB will have a copy on emailB2... so I just zip up all the *2 accounts to backup.

the emails are in xvmailhome/domains/myDomain/emailA emailB and so on...
my old command below will create with a super huge Zip of all the user accounts ending with *2,

cd /xvmailhome/domains/MyDomain.com
tar cvf /backup/MyDomain.gz *2                'This command tars only those accounts ending with *2
rm -rf ./*2        'deletes all the emails inside the accounts ending with *2

but instead of that, I want a Zip file for each email account... so instead of MyDomain.gz
I will end up with   /MyDomain/emailA2.gz ,   /MyDomain/emailB2.gz ,   /MyDomain/emailC2.gz

one zip per email account...
0
 
dennisdominicAuthor Commented:
strange.. but it works now.
btw, what's the difference between .tar.gz and just .gz?


for dir in *2
do
    tar czf /backup/myDir/$dir.tar.gz  $dir
done
0
 
omarfaridCommented:
Hi,

I have no idea.

So, the subdirs can be backed up now.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.