Preparing the Old Server for Migration
To initiate the migration process, the first step is to prepare the old server by copying all the required data into a migration folder and compressing it for transfer to the new server. You can accomplish this using the tar
command as follows:
tar -czvf name-of-archive.tar.gz /path/to/directory-containing-migration-files
Transferring Data Securely
The next phase involves transferring the data securely to the new server using rsync
commands.
rsync -rav -e "ssh -i /root/.ssh/id_rsa" your_user_name@IP_Address:/migrateThis/appMigrate /MigrationNew
Importing and Decompressing Data
After transferring the data, import the migration compressed file and decompress it on the new server. For each folder replaced on the new server, it’s advisable to create a backup first, replace the original folder with the migrated one, and thoroughly test to ensure everything functions correctly.
tar xvzf appMigrate.tar.gz
Configuring Firewall and SSL Certificates
Open ports 80 and 443 on the new server.
sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
sudo service iptables save
If the servers are on a managed platform ensure you follow the provided instructions to create new policies for ports 80 and 443 on the manged firewall.
To install and configure SSL certificates, refer to the provided link for instructions on installing Certbot. After installation, run Certbot from the command line to update the SSL certificates. Set up a cron job to automatically renew the certificates as needed.
Transferring Database and User Accounts
Use rsync
to copy all MySQL databases, users, permissions, and data structure from the old server to the new one.
rsync -avz /var/lib/mysql/* user@example.com:/var/lib/mysql/
For transferring user accounts, follow the provided instructions to create a tarball of old users on the old Linux system.
Instructions for Filtering User Accounts
The process varies depending on the Linux distribution, with different default UID and GID values and upper limits. Here’s how to handle it:
For RHEL/CentOS/Fedora Core systems, the default UID starts at 500, with an upper limit of 65534 as specified in /etc/libuser.conf
.
For Debian and Ubuntu Linux, the default UID starts at 1000, with an upper limit of 29999 as specified in /etc/adduser.conf
.
To ensure that only regular user accounts are included in the migration, set up the UGIDLIMIT
variable to the appropriate start limit for normal user accounts. This value should match the configuration of your Linux distribution.
export UGIDLIMIT=500
Then, use awk
to filter out system accounts based on the specified UID limits. Pass the UGIDLIMIT
variable to awk
using the -v
option, which assigns the value of the shell variable UGIDLIMIT
to the awk
program variable LIMIT
. Set the field separator to :
with -F:
. The awk
command reads each line from /etc/passwd
, filters out system accounts according to the defined limits, and generates a new file /root/move/passwd.mig
. The same logic applies to the rest of the awk
commands for other files.
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
Creating Backups of User Data
Before proceeding with the migration, it’s crucial to create backups of user data, including the /home
and /var/spool/mail
directories. Use the tar
command to compress and archive these directories:
tar -zcvpf /root/move/home.tar.gz /home
tar -zcvpf /root/move/mail.tar.gz /var/spool/mail
Once the backups are created, use a secure method such as scp
, USB pen drive, or tape to copy the /root/move
directory to the new Linux system.
Instructions for Restoring User Accounts on the New System
On the new Linux system, begin by making a backup of the current users and passwords to ensure data integrity:
mkdir /root/newsusers.bak
cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newsusers.bak
Next, navigate to the location of the migrated files and restore the passwd
, group
, shadow
, and gshadow
files from the backups:
cd /path/to/locationOfOldFiles(Migrated)
cat passwd.mig >> /etc/passwd
cat group.mig >> /etc/group
cat shadow.mig >> /etc/shadow
/bin/cp gshadow.mig /etc/gshadow
Ensure that the >>
(append) shell redirection is used to add to existing files without overwriting them.
Finally, extract the backed-up user data from the /home
and /var/spool/mail
directories on the new server:
cd /
tar -zxvf /path/to/location/home.tar.gz
tar -zxvf /path/to/location/mail.tar.gz
That’s it and good luck!