Here’s the SSH command to import a database backup to a new database.
Navigate to the directory where your database copy resides using SSH.
mysql -uusername -p databasename < backupname.sql
You’ll be prompted for the password for the database. Enter that.
If this is a Magento database, it could take awhile to import. Ours is around 600M, so it took awhile.
That’s it.
Part of the transfer or migration of a website many times involves a database. If you are on an “ix” server, SSH is a great way to backup your MySQL database.
Here’s how you do it:
Using SSH, navigate to your httpdocs or public folder on your server where the website resides.
Use the following command.
mysqldump –opt -Q -u dbusername -p databasename > /path/to/backupname.sql
This creates a copy of your database.
Now, you can transfer that database backup to your new server.
If you ever have a need to migrate a website from one server to another, it can be a huge deal, especially when dealing with Magento, which has tens of thousands of files. Also, if your Magento store has many products, you have all those thousands of image files to move too. You could try FTP, but usually our servers hang during a large transfer. Even if you could do it by FTP, it would take hours at best to transfer a complete Magento site.
So here’s how to do a complete site migration using SSH. This can be used for any website you have root access to, not just a Magento site.
1. Login to server 1 via SSH and open the folder which you want to backup. You’ll probably need to login as root user.
Use this commands:
cd /home/somepath/to/yourwebsite/public_html
2. Make a compressed archive out of this folder using the command
Next:
tar -cvf sitepack.tar ./
3. Login to server 2 via SSH and use the command below to fetch the backup from server
wget yourdomain.com/sitepack.tar
4. Now uncompress the archive using the command
tar -xvf sitepack.tar
This is the easiest way we know of to move large websites with tons of files.
If you’re changing the directory structure of a website and you want to keep your pages indexed with Google and the other search engines, here’s an option for you, especially if you have a large number of pages to redirect.
Use the RedirectMatch command on Apache Servers.
In your .htaccess file, use the following code example:
RedirectMatch 301 /old-top-category/old-sub-category/.* http://www.your-domain.com/new-category.html
This will redirect all page or file calls from the previous directory to the new directory, on your same site. You could also use this to redirect to a different website.