-
Start ssh Sessions
-
Start an ssh session to your source website host and change to the user home directory.
ssh host.server.com
cd ~ - Repeat the above steps on the destination website host server
-
Start an ssh session to your source website host and change to the user home directory.
-
Create an archive folder.
-
Make a new folder to store your backup files with the command…
mkdir archive
- Repeat the above step on the destination website host server
-
Make a new folder to store your backup files with the command…
-
Archive the website files
Use tar on the source server to make a compressed copy of all your site files with the command…
tar -czvf ~/archive/mysiterootfolder-yyyy-mm-dd.tar.gz -C ~/html mysiterootfolder
Note the space between “-C ~/html” and “mysiterootfolder”A quick explanation of the above command…
tar runs the program which compresses files
-zcvf are the options selected when running the tar program
c = create a compressed file
z = use gunzip compression
v = verbose (output all the program’s actions while it’s running)
f = create a file
The 1st path (~/archive/……) is the path of the compressed file you wish to create-C = Change to directory specified by the 2nd path – (~/html) This prevents the entire path from root being created in the archive
The 3rd path (~/mysiterootfolder/……) is the path to the folder you want to make a compressed copy of. -
Copy Backup to the New Server Using rsync
Either execute rsync on the source server to copy the compressed backup file from the original server to your second hosting server with the command
rsync -azv --partial-dir ~/rsync-partial ~/archive/mysiterootfolder-yyyy-mm-dd.tar.gz user@host.server2.com:~/archive/
Or execute rsync on the destination server to copy the compressed backup file from the original server to your second hosting server with the command
rsync -azv --partial-dir ~/rsync-partial username@host.server.1.com:~/archive/mysiterootfolder-yyyy-mm-dd.tar.gz ~/archive/
A quick explanation of the above commands…
rsync runs the program which transfers the files
-azv –partial-dir are the options used to make rsync behave in the desired way
a = specifies that any sub-directories and nearly all files are included
z = compress file to speed up the transfer
v = verbose (output all the program’s actions while it’s running)
partial-dir = creates a temporary copy of the file being transferred in the specified directory which can be resumed from if the transfer is interrupted part way. The directory is automatically resumed once the transfer is complete. This saves have to start the transfer again from scratch if it has previously failed. -
Unzip the archive on the destination server
Use tar on the destination server to make a decompress the site files with the command…
tar xvf archive/mysiterootfolder-yyyy-mm-dd.tar.gz -C public_html/
-
Export the Site Database and Transfer to the New Server
- Export site database to a file on the source server
mysqldump -u database_username -p database_name -hdatabase_host_address > ~/archive/sitename-yyyy-mm-dd.sql
- Transfer site database file to the destination server by executing rsync command on the destination server
rsync -azv --partial-dir ~/rsync-partial username@host.server.1.com:~/archive/sitename-yyyy-mm-dd.sql ~/archive/
- Create a new database on the destination server
The steps for this are typically to use the host providers mySql interface to- Create a new database, giving it the same name as the original database
- Create a new database user, giving it the same name as the one used with the original database
- Add the new user to the new database
- Export site database to a file on the source server
-
Import the database file into the new database on the destination server
mysql -u database_username -p database_name < ~/public_html/sitename/sitename-yyyy-mm-dd.sql
-
Edit Database Configuration
- Open the website config file
This scenario assumes WordPress is being used whereby wp-config.php must be edited
vi ~/public_html/mysiterootfolder/config-php
- Edit database related parameters to reflect the new database
DB_NAME
DB_USER
DB_PASSWORD
DB_HOST
- Open the website config file
-
Setup the Domain on the Hosting Server
- Go to your hosting provider’s domain or Add-on domain configuration page
- Enter the domain details including Domain name, Subdomain and the Document root e.g. public_html/sitename.com
- Confirm the addition
-
Edit DNS Configuration
- Go to your site domain provider’s configuration page
- Edit or enter the A record to reflect the new server ip address
Categories
How to Move a Website to a New Server
