source: bin/qtp-restore @ 3

Revision 3, 8.8 KB checked in by jake, 6 years ago (diff)

Brought up to date for new packages

  • Property svn:executable set to *
Line 
1#!/bin/sh
2
3###################################################################################
4# PLEASE READ THE COMMENTS!!! They contain important info! You've been warned!    #
5###################################################################################
6
7# Version 3.0.1 - October 30th, 2007 - Jake Vickers <jake@v2gnu.com>
8# Fixed a cp -rf command to a cp -af to retain the time stamps of the messages.  Thanks to
9# Aaron Sprulock for that one!
10
11# Version 3.0  -  October 14th, 2007 - Jake Vickers <jake@v2gnu.com>
12# Changed a couple options - mysqlroot password is no longer required to be hard coded, it asks.
13# The script will now backup the original /var/qmail/control files before restoring the backup copies.
14# The script now also tells you that the backup file NEEDS to be in /root to continue.
15
16# Version 2.9  -  November 7th 2006  - Jake Vickers (jake@v2gnu.com)
17# I'm changing the format of the comments (newest at top), as well as changing the versioning to match the backup
18# script versioning for ease of identification.
19# This revision adds a few more files to be restored, since they are now backed up in the backup script
20# To highlight a few of the restored files: SquirrelMail prefs and address books are now restored; DJBDNS is now restored (if it exists);
21# all your control files are now restored; the /admin-toaster/ password is now restored; SpamAssassin stuff is now restored
22# There are a few more things that get restored as well, but those are the highlights.
23
24# Version 1.0  -  April 14th 2005
25
26# QMail restore script written by Jake Vickers - jake@v2gnu.com
27# Script created from research and notes by Jeremy Gall - jeremy@thewardrivers.com
28
29# This script is provided AS-IS, with no warranties expressed or implied, no promises,
30# no good intentions, or any other way you could think of to try and blame something on me.
31# Use this script at your own risk, and be aware it may not work for you.
32
33# This script may be obtained from http://v2gnu.com/qmail/qmail-restore-script.tar.gz
34# This package will include any scripts I obtained from other people to use and/or modify.
35# Backups are created with a modified version of Nate Davis's backup script
36# which is no longer on his website.
37# This script also uses the queue_fix Python program written by
38# Charles Cazabon - pqt@discworld.dyndns.org
39
40# To restore your QMail installation, start with a new machine, and do an install of
41# Qmail. If you use any other install schemes, you may need to edit
42# some of this script, and/or some other files. Most notable is the /var/qmail/users/assign file.
43# The UID/GID of the vpopmail user must be correct with the machine you are trying to install on!
44# This script assumes a vpopmail UID/GID of 89:89
45# This script assumes your backup file is on the /root directory, and was created using the
46# naming scheme in my modified backup script. Edit to suit your wants/needs.
47# This script also assumes you have Apache back up and running correctly. You'll need to put the
48# includes for qmail in on your own
49# This script also assumes the new server will have the same IP address as the old one. If not,
50# you'll need to edit the qmail control files on your own.
51
52# Version 1.1 - July 18th 2005
53# Removed the mysqldump importing. Didn't work with the new toaster system on my machine,
54# although it may still work on yours. Also added the command to create the database before
55# dumping info into it <grin> Hate it when I miss things!
56# Last thing added was the conversion of the old .qmail-alias format to the MySQL format now used.
57
58echo ""
59echo "This is the qtp-restore script written by Jake Vickers <jake@v2gnu.com>. It comes with no"
60echo "warranties, guarantees, or anything else. It may NOT work for you. I have not tested this"
61echo "script thoroughly, so if you have an issue please email me and let me know so I can resolve"
62echo "it for others."
63echo ""
64echo "Your backup file will NEED to be in /root to continue...."
65echo "This script -WILL- also overwrite -ANY- qmail configs, users, domains, etc. that you may"
66echo "have previously configured."
67echo ""
68echo "Do you wish to continue? y/[n]"
69asking=n
70read asking
71if [ $asking = "n" ] ; then
72        echo ""
73        echo "Aborting, per user request."
74        exit 0
75fi
76
77#################################################
78#      Set the variables below!!!
79#################################################
80
81read -p "Please enter your MySQL Root password: " mysqlrootpass
82
83queuerepairdownload="http://pyropus.ca/software/queue-repair/queue-repair-0.9.0.tar.gz"
84DATENAME=`date +%Y%m%d%H%M`
85
86#################################################
87#      I can't think of any more variables I
88#      need, so here's the restore script!
89#################################################
90
91# We're stopping QMail (if it's running), and uncompressing all the archives.
92# Then we move them back to where they're supposed to be
93
94cd /root
95if test -e /root/queue-repair-0.9.0/queue_repair.py
96        then
97                echo "Queue repair exists for use"
98        else
99                echo "Retreiving and installing Queue Repair python script"
100                wget $queuerepairdownload
101                tar xzvf queue-repair-0.9.0.tar.gz
102fi
103
104tar xzvf *-backup.tar.gz
105qmailctl stop
106echo "Backing up old /var/qmail/control files before restoring.... (they will be in /root)"
107tar czvf /root/qmail-control-$DATENAME.tar.gz /var/qmail/control
108
109echo "Restoring assign file"
110tar xjvf *-assign.tar.bz2
111cd var/qmail/users
112cp -rf assign /var/qmail/users/
113echo
114echo "Restoring qmailcontrol files"
115cd /root
116tar xjvf *-qmailcontrol.tar.bz2
117rm -rf /var/qmail/control
118mv -f control /var/qmail
119echo
120echo "Restoring vpopmail files"
121cd /root
122tar xjvf *-vpopmail.tar.bz2
123cd home/vpopmail
124cp -af domains /home/vpopmail/
125cd /home/vpopmail/domains
126chown -R vpopmail:vchkpw *
127echo
128cd /root
129echo "Restoring spamassassin files"
130if test -e /root/.spamassassin/user_prefs
131        then
132                echo "Spamassassibn file already exists"
133        else
134                echo "Creating default prefs file and folder"
135                mkdir -p /root/.spamassassin
136                cp /usr/share/spamassassin/user_prefs.template /root/.spamassassin/user_prefs
137fi
138
139tar xjvf *-spamassassin-files.tar.bz2
140rm -rf /home/vpopmail/.spamassassin
141cp -rf /root/.spamassassin /home/vpopmail/
142echo "Performing permission/sanity check on spamassassin files"
143echo
144chown -R vpopmail:vchkpw /home/vpopmail/.spamassassin
145chmod 600 /home/vpopmail/.spamassassin/*
146chmod 644 /home/vpopmail/.spamassassin/user_prefs
147cd /root
148echo
149if test -e /root/*-djbdnsfiles.tar.bz2
150        then
151                echo "Restoring DJBDNS files"
152                tar xjvf *-djbdnsfiles.tar.bz2
153                rm -rf /var/djbdns/service/dnscache/env
154                rm -rf /var/djbdns/service/dnscache/root
155                mv -f env /var/djbdns/service/dnscache/
156                mv -f root /var/djbdns/service/dnscache/
157fi
158echo "Restoring Squirrelmail prefs and address books"
159tar xjvf *-squirrelmail-prefs.tar.bz2 -C /var/lib/squirrelmail/prefs/
160echo
161cd /root
162echo "Restoring Squirrelmail plugins"
163rm -rf /usr/share/squirrelmail/plugins
164tar xjvf *-squirrelmail-plugins.tar.bz2 -C /usr/share/squirrelmail/
165echo
166echo "Restoring admin-toaster password"
167if test -e /usr/share/toaster/include/admin.pass
168        then
169                echo "Backing up original admin.pass file as admin.pass.orig"
170                mv -f /usr/share/toaster/include/admin.pass /usr/share/toaster/include/admin.pass.orig
171fi
172tar xjvf *-qmailadminpasswd.tar.bz2 -C /usr/share/toaster/include/
173echo
174echo "Restoring mysql database"
175cd /root
176gunzip -d *-vpopmail.sql.gz
177# We had a quirky problem - if the database file had an extension, it didn't get imported right
178mv *-vpopmail.sql vpopmail
179
180########################################################################################
181#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
182#       This next command destroys anything you may have in the vpopmail MySQL
183#       database up to this point! We warned you!
184#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
185########################################################################################
186
187mysqladmin -uroot -p$mysqlrootpass flush-tables
188mysqldump -uroot -p$mysqlrootpass vpopmail > /usr/share/toaster/include/vpopmail.orig
189mysqladmin drop -f vpopmail -uroot -p$mysqlrootpass
190mysqladmin create vpopmail -uroot -p$mysqlrootpass
191
192mysql -uroot -p$mysqlrootpass vpopmail < vpopmail
193mysqladmin -uroot -p$mysqlrootpass reload
194mysqladmin -uroot -p$mysqlrootpass refresh
195# Now we're going to change the permissions on the queue_repair utility, and run it to fix
196# any problems that may have been missed, and to fixed iNodes for the mail that was still in
197# the queue when the archive was created on the original machine
198cd /root
199cd queue-repair-0.9.0
200chmod 777 queue_repair.py
201./queue_repair.py -r
202cd /root
203/var/qmail/bin/qmail-newu
204
205mysqladmin -uroot -p$mysqlrootpass reload
206mysqladmin -uroot -p$mysqlrootpass refresh
207service httpd reload
208
209###  Convert old .qmail aliases to new format
210#/home/vpopmail/bin/dotqmail2valias -a
211qmailctl cdb
212qmailctl start
213echo "Restore Complete!"
214# Now everything should be up and running again, with everything restored to when you did the
215# backup.
216
Note: See TracBrowser for help on using the repository browser.