We make a dump (backup) of the database using the mysqldump utility. Making a backup of MySQL databases Diary Maxim Bogolepov Backup of mysql databases

Hi all! There are situations when, after installing a new extension or theme on an online store website, various unforeseen situations arise. They consist in the fact that errors may appear on the site that were not there before, or the site may not respond at all. To be prepared for such situations, you need to make backup copies of your site or backup. Ideally, they should be created manually every time you install a new module on the site, or perform operations that affect the database or site files. I make backups every week just in case. I just always get a lot of updates in a week.

Manually backing up site files

As a rule, good hosting providers have their own data backup system. It makes a backup of your site with a certain period, usually several days. It is clear that you should not completely rely on hosting for backup. How then can you make a backup copy? We will use .

The first step is to create a backup copy of your files. To do this, go to the “WebFTP” section. Here we select the site whose files we want to back up and go to its folder. Then, for faster downloading, the files must first be zipped. You can archive files with or without compression. I would recommend not compressing the files, and adding them to the archive in their normal form, so as not to damage them in the future. We select the directories and files we need, in the drop-down list below, select the “Pack to archive” action. We give it a name, preferably indicating the date and time when the copy was created. Click the “Run” button.

We are waiting for some time for the archive to be created. After that, download it to your computer. The backup copy of the files is ready.

Manual database backup

Now let's move on to an equally important step - database backup. If the hosting does not provide the ability to do this automatically, then in such cases, in order to save copies on your computer, you need to export the database. This is done as follows. Go to the “Databases” section and click on the “PHPMyAdmin” link opposite the desired database.

In the open tab, enter your username and password, and we get to the MySQL database control panel. Click on the name of the database (1) that you want to reserve and go to the “Export” tab (2).

Select a method with a minimum of settings and click “Forward”. After which the download of the sql file with a copy of the database will begin.

Restoring a database from a backup

To restore the database from this file, you will also need to log into the MySQL database control panel, delete all existing tables in the database and then go to the “Import” tab. There, select the previously created file and click on the “Let’s go” button. The system will download it and notify you that the operation is complete. All the tables that it contained at the time the backup was created will be created in the database.

Restoring files from a backup

With file recovery, everything is a little simpler. We go to the “WebFTP” section, then to the folder of your site, delete all the files inside the folder of your site and click “Upload file”. Select the previously created archive and click “Upload file”. We are waiting for the download to finish.

After the archive has downloaded and is displayed in the files panel, you need to unzip it. And everything is ready. Or, without deleting the files, you can simply download the archive and unzip it and replace it. If the unzipping was successful, this means that all files have been replaced from the backup copy. But I usually delete the files first and then unzip the backup.

You can also download files using an FTP client, such as FileZilla. I wrote about how to work with him. We connect to our ftp account through the client, go to the folder with the site files and simply copy them to your computer. In the same way, they can be uploaded from your computer to the hosting. Just don’t forget to copy and replace.

Don't forget about the security of your site, take backups seriously because you never know when they might come in handy.

Best regards, Schmidt Nikolay

Hello, dear readers of the blog site. Today I want to talk about the concept of backing up files and databases of your resource.

Yes, of course, many hosters () perform backups automatically and, if something happens, you can turn to them for help. But as they say: rely on the hoster, but don’t make a mistake yourself.

Situations in which you may lose your project data, you can cite a lot, and you yourself have probably heard about it. You shouldn't rely on the mercy of your host. You need to make a backup yourself and store it on your computer.

This will be much more reliable and calmer. If, after all, your Internet project has collapsed, and there is nothing to restore it from, then try your luck in Webarchive (written about it in more detail here), because it constantly makes snapshots of the vast majority of sites on the Internet.

How to backup website files using FileZilla

As you probably already know, sites created on the basis of any engine, be it Joomla, WordPress or SMF, consist of two important parts:

  1. Firstly, these are the actual files of the engine and the extensions installed in it, pictures and...
  2. And secondly, these are databases where the texts of your articles, posts, etc. are stored.

The database (DB) can also store settings for some parameters of the engine and its extensions. I already wrote about this in an article about. Such an organization has many advantages.

So our task comes down to backing up all this wealth. Moreover, the frequency of database backup is usually determined by the frequency of new information appearing on your project. The optimal way, in my opinion, is to copy the database daily. Fortunately, they usually don’t weigh very much and such backups are carried out very quickly. You should probably update backup copies of your project files only after you have made some changes to them: installed some extensions, updated the engine version, etc.

Let's start, perhaps, with our first assistant called FileZilla, although you can use any other FTP manager instead, up to , but I prefer this particular free software creation. I have already described them in some detail in the above article, therefore we will not dwell on this in detail (if you want, read for yourself, especially about storing passwords in this program and the problems associated with it).

Let's look at how to backup files using it. Once you have access to your hosting server, you should go to the root folder (usually called public_html or htdocs). The remote server in Filezil is displayed on the right, and the contents of your computer are displayed on the left.

If you plan to make backups regularly, then I advise you to create a folder on your computer’s hard drive with a “speaking” name, and inside it there are directories with the names of your projects. Inside these directories, you can create folders with the current date, into which the files of your web project will be copied. Thanks to this, it will then be easier to navigate through backups and delete very outdated ones to free up space.

Now open on the left side of FileZilla the folder where the backup will be carried out, and on the right side - the root folder of the website. I advise you to enable the ability to show hidden files in the settings of this program: in the top menu, select “Server” - "Force hidden files to be shown".

This is necessary so that hidden files, such as .htaccess, are included in your backup. Next, you select all the objects on your site in the root directory while holding down the Shift button on your keyboard. Right-click on the selected objects and select the item from the context menu "Download".

File backup will begin, which may take quite a long time - depending on the number and total weight of the objects being copied, as well as the speed of the server. But you don’t have to watch the process of creating a backup. While copying, you can go about your business without closing Filezilla, of course.

At the end of the process you will feel better pack everything downloaded into one archive, because this can significantly reduce the volume and number of stored objects. After archiving, you leave only one archive, and delete everything downloaded - everything will be nice and neat. To restore site files from such a backup: you will need to unpack it and copy the contents of the archive to the server in a manner similar to that described above.

True, if you packed the files into a ZIP archive, then you can upload it to the server and unpack it there (described here how). But in this case, some troubles may arise later, which can be solved by PHP means (read the link about access rights and changing Cmod programmatically).

How to make a database backup using phpMyAdmin

Let's see how to backup a database using phpMyAdmin script. It can be accessed from your hosting control panel. If you have, then in order to launch phpMyAdmin, you need to follow the following path: find the area called “Databases” on the cPanel main page and click on the icon of this script there.

If your hosting does not have access to this script, then you you can do it yourself to the root folder of your site and access your database through it. You can download the program from here.

After downloading the archive to your computer, you must unpack it and upload the resulting folder (for simplicity, you can first rename it to phpmyadmin) into the root directory. In general, that's all. Now all that remains is to enter the following URL in the address bar of your browser: http://vash_sait.ru/phpmyadmin

In any case, the PhpMyAdmin program window will open, with which we can easily backup your project databases. This is the main page of the program (on some sites I have a slightly outdated version, but I just got used to it):

If you are on any other phpMyAdmin page, then in order to get to the main page, you need to click on the house highlighted in the picture. On one account with the hoster you can have many databases and therefore you must first choose from the left menu base, which you want to back up.

You can see the list of databases in the program window on the left (under the house icon). In order to make a database backup you will need to click on the tab "Export" above the list of tables.

At the bottom of the page that opens, check the box "gzip". And click the "ok" button.

True, this is in the old (convenient) version of the script. Now, by default, you are offered to quickly download the database without compression, and if you want to customize something (including activating its gzip compression on the fly), you will need to check the “Normal” box and select gzip among many other settings , which is not very convenient in my opinion.

As a result, after some time (which depends on the speed of the server, its load and the size of your database), a standard copy dialog will open, in which you must select the location to save the backup of this database.

Restoring a database from a previously created backup

To restore a database from a backup, you need to proceed as follows. First, you must clear the existing database of all tables. To do this, you log into the phpMyAdmin program, select the desired database that you want to restore in the left column.

In the window that opens with the tables of this database, go down to the very bottom and under the list of tables click on "Select all". Then, again at the bottom of the page, select the item “With marked” from the drop-down list "Delete".

A window will open with a list of all tables to be deleted. You click on the “Yes” button.

You can now restore the database from a previously made backup. To do this, select the bookmark "Import":

In the window that opens, click on the “Select file” button and find the previously made backup of this database on your hard drive. Click on the “Forward” button (or “OK” in older versions of the script) at the bottom of the page and wait for the download to finish (the time again depends on the speed of the server and the size of the database). All.

Having up-to-date file backups and database backups on your computer, you can sleep peacefully. They can also be used when moving a site to another hosting.

Transferring a site to a new hosting

So, how can we transfer the site to a new location? After purchasing hosting, you will be provided with data to access the hosting server via FTP, which you will enter into the Filezila program to gain access to the server.

First, unzip the backup data on your computer and place it in the root folder, similar to the process described above. Without waiting for the files to be copied, you can begin restoring database tables from a backup made at the old location of your resource.

But for this you need to first go to a new hosting (where the tables you saved will be copied later). You will learn how to do this from the article about phpMyAdmin, the link to which I provided just above. Please note that you most likely will not be able to choose the same name for the database and its user as at your previous place of residence. The fact is that hosting usually adds your login to the database name you choose.

Therefore, after finishing copying the files and database, before accessing the site from the browser, you should enter the appropriate changes to your website engine settings. To do this, you will again need to access the site files via FTP and make changes to the configuration files of one or another engine (Joomla, WordPress, SMF, etc.). Let's look at the settings for each engine separately.

What to change in WordPress settings when migrating it

Transferring a blog to WordPress will require changing the following settings. You will need to open the file for editing using FileZilla WP-CONFIG.PHP, which is located in the root directory on the server. In it you need to edit the lines responsible for the name of the database and the user.

// ** MySQL settings - You can get them from your host ** // /** Database name for WordPress */ define("WP_CACHE", true); //Added by WP-Cache Manager define("DB_NAME", "enter the new name of your database here"); /** MySQL username */ define("DB_USER", "enter new username here"); /** MySQL database password */ define("DB_PASSWORD", "anipiimaaxai"); /** MySQL server - sometimes you need to change this value, for example, on Masterhost */ define("DB_HOST", "localhost"); /** Database encoding used when creating tables. */ define("DB_CHARSET", "utf8"); /** Database mapping. DO NOT CHANGE THIS VALUE. */ define("DB_COLLATE", "");

After editing, save this file back and you can consider that the transfer of WordPress to the new hosting has been successful. If you change the domain name when transferring your blog, then in order for everything to work correctly, you will need to open the backup copy of the database with the SQL extension in a text editor (extract it from the gzip archive).

Next, using the built-in “search and replace”, find all references to the old URL of your blog and replace its new address (for example, vasy.ru with vova.ru). After this, save the file with the database backup and “Import” it in the phpMyAdmin program.

After you log into the WordPress admin area, you will need to enter the correct absolute path to the objects of your blog (it has changed because you moved WordPress to another hosting). The absolute path is set via the UPLOAD_PATH parameter in the global WP settings. You can get to these settings by adding the following path to the URL of the main page:

/wp-admin/options.php

For my blog address it will look like this:

Https://site/wp-admin/options.php

But first you need to log in to the WordPress admin. read the link provided.

What needs to be changed in Joomla settings when changing hosting

Transferring a Joomla website to another hosting will require changing the following settings. You will need to open for editing CONFIGURATION.PHP in the root folder of the server. Find the lines in it that are responsible for gaining access to the database:

Var $user = "enter new username here"; var $db = "enter your new database name here";

In addition, you will also need to change the absolute path to the folders for storing logs and temporary files in Joomla. You need to change it in these lines:

Var $log_path = "/home/xxxxx/public_html/logs"; var $tmp_path = "/home/xxxx/public_html/tmp";

Transferring the SMF forum to a new hosting

Migrating the forum to SMF will require changing some settings. You will need to open it for editing SETTINGS.PHP from the forum root folder. Just as in the case of Joomla, here you will also need to not only change the name of the database and SMF user, but also the absolute paths to the forum folder and the forum SOURCES folder.

########## Database Info ########## $db_server = "localhost"; $db_name = "enter your new database name here"; $db_user = "enter new username here"; $db_passwd = "hoighaebaeto"; $db_prefix = "smf_"; $db_persist = 0; $db_error_send = 1; ########## Directories/Files ########## # Note: These directories do not have to be changed unless you move things. $boarddir = "/home/xxxx/public_html/forum"; # The absolute path to the forum"s folder. (not just "."!) $sourcedir = "/home/xxxx/public_html/forum/Sources"; # Path to the Sources directory.

But besides this, after transferring SMF to a new hosting, you will need to change the absolute path to the currently installed folder. To do this, you will need to go to the forum admin area and select “Current theme” from the left column. In the window that opens, in the “Theme folder” area, you enter the absolute path to the desired folder.

How to start working with a website immediately after transferring it to a new hosting

You attached yours (website, in my case) to it. Or you, in accordance with the above, carried out the transfer. In principle, it doesn't matter, but you will have to associate the new server with the domain anyway. To do this, you will find your new host in the control panel of your registrar (where you purchased the domain name).

You can see the DNS server addresses in the letter your new hoster will send you. Where exactly you need to enter these DNS in the registrar panel, it’s hard to say for sure, but it should not be buried deeply and lie in plain sight. As a last resort, contact technical support.

So, despite the successful transfer of the site to a new host, you still have to wait from several hours to a couple of days while your domain is being delegated. Until this process is completed, your resource will not be available at your new location.

Sometimes the hosting owner may indicate in a letter a technical address at which you can access your resource while the records on all DNS servers on the Internet are updated. But this doesn't always happen. In addition, for example, for WordPress, the technical address will not allow you to fully start working with the newly transferred blog, because this engine is strictly tied to the domain name.

But the owner of the host always indicates the IP address of your new server in the letter. Using it, you can access your resource without waiting for DNS registration. But in this case, only you will get access and only on the computer where you make the settings described below. So, you need to do the following:

  1. using any file manager, open for editing (follow this link you will find a detailed article on where this file is located, how to find it in Windows 7 and what should be written in it), located in the following path: c:\Windows\System32 \drivers\etc\hosts
  2. at the end of the HOSTS content you need to add the line: 109.77.43.4 site where at the beginning there is the IP address of the new server, and after it, separated by a space, the domain
  3. save this file and you can safely type in your browser the address of the resource that you just transferred (you may need to reset the DNS cache on your computer - read about this in the article just above about the Hosts file)

Thus, without waiting for the domain to be delegated, you can already check the functionality of the transferred resource and, if necessary, fix everything before it becomes available to all other visitors. After the domain is delegated, you will need remove added line in HOSTS.

You can also look at a video on the topic from a well-known website builder in RuNet:

Well, and a selection video tutorials on transferring a Joomla CMS website to hosting I advise you to look. They will be played one after another automatically, and if you want, you can switch to the next lesson using the corresponding button on the player panel or select the desired lesson from the drop-down menu in the upper left corner of the player window:

Enjoy watching!

Good luck to you! See you soon on the pages of the blog site

You might be interested

February 1, 2012 at 00:33

Backing up data in MySQL

  • MySQL

Database backup is a thing that always has to be configured for already running projects directly on “live” production servers.
This situation is easily explained. At the very beginning, any project is still empty and there is simply nothing to copy. In the phase of rapid development, the heads of a few developers are exclusively occupied with screwing in features and frills, as well as fixing critical bugs with a deadline of “the day before yesterday.” And only when the project “takes off” comes the realization that the main value of the system is the accumulated database, and its failure will be a disaster.
This review article is for those whose projects have already reached this point, but the roast rooster has not yet taken the bait.

1. Copying database files

The MySQL database can be copied if you temporarily turn off the MySQL server and simply copy the files from the folder /var/lib/mysql/db/. If the server is not turned off, for obvious reasons, data loss and corruption is likely. For large loaded databases this probability is close to 100%. In addition, the first time you start with a “dirty” copy of the database, the MySQL server will begin the process of checking the entire database, which can take hours.

In most live projects, regularly shutting down the database server for a long time is unacceptable. To solve this problem, a trick based on file system snapshots is used. A snapshot is something like a “photo” of the file system at a certain point in time, taken without actually copying the data (and therefore quickly). Lazy copying of objects works in a similar way in many modern programming languages.
The general scheme of actions is as follows: all tables are locked, the database file cache is reset, a snapshot of the file system is taken, and the tables are unlocked. After this, the files are quietly copied from the snapshot, after which it is destroyed. The “blocking” part of such a process takes about seconds, which is already tolerable. As a payback, for some time, while the snapshot is “alive,” the performance of file operations decreases, which primarily affects the speed of write operations to the database.

Some file systems, such as ZFS, support taking snapshots natively. If you don't use ZFS, but have an LVM volume manager on your server, you can also copy the MySQL database via snapshot. Finally, under *nix you can use the R1Soft Hot Copy snapshot driver, but this method will not work in the openvz() container.

For MyISAM databases, there is an official free utility mysqlhotcopy, which “correctly” copies MyISAM database files without stopping the server. There is a similar utility for InnoDB, but it is paid, although it has more features.

Copying files is the fastest way to transfer an entire database from one server to another.

2. Copying via text files

In order to read data from the production database into backup, it is not necessary to pull the files. You can select data using a query and save it to a text file. To do this, use the SQL command SELECT INTO OUTFILE and its pair LOAD DATA INFILE . Unloading is done line by line (you can select only the necessary lines for saving, as in a regular SELECT). The structure of the tables is not specified anywhere - the programmer must take care of this. It must also take care to include SELECT INTO OUTFILE commands in the transaction if necessary to ensure data integrity. In practice, SELECT INTO OUTFILE is used for partial backup of very large tables that cannot be copied in any other way.

In most cases, the mysqldump utility created by Igor Romanenko is much more convenient. The mysqldump utility generates a file containing all the SQL commands needed to completely restore a database on another server. Using separate options, you can make this file compatible with almost any DBMS (not only MySQL); in addition, it is possible to download data in CSV and XML formats. To recover data from such formats, there is a utility called mysqlimport.

The mysqldump console utility. There are its add-ons and analogues that allow you to manage backup via a web interface, for example, the Ukrainian tool Sypex Dumper (their representative is on Habré).

The disadvantages of universal backup utilities to text files are the relatively low speed of operation and the inability to make incremental backups.

3. Incremental backups

Traditionally, it is recommended to keep 10 backups: one for each day of the week, as well as backups from two weeks, a month and a quarter ago - this will allow you to roll back quite deeply in the event of any data corruption.
Backups should definitely not be stored on the same disk as the live database, and not on the same server. In case of fires and other disasters, it is best to rent a couple of units in a nearby data center.

These requirements can be a problem for large databases. Uploading a backup of a 100-gigabyte database over a 100-Mbit network will take about three hours, during which the channel will be completely clogged.
Incremental backups can partially solve this problem, when a full backup is made, say, only on Sundays, and on other days only data added or changed over the past day is written. The difficulty is how to identify this very “data that has changed during the day.”

Here, the Percona XtraBackup system, which contains a modified InnoDB engine, analyzes MySQL binary logs and extracts the necessary information from them, is practically unrivaled. The paid InnoDB Hot Backup mentioned above has almost the same capabilities.

The general problem with any backups is that they always lag. In the event of a fatal failure of the main server, it will be possible to restore the system only with some “rollback” in time, which will very, very disappoint its users. If financial flows in the system were somehow affected, such a “kickback” can literally cost a pretty penny.

4. Replication

The MySQL replication system is designed to avoid rollbacks. The idea of ​​replication is based on the fact that in addition to the “main” server (“Master”), MySQL servers (“slaves”) are constantly running, which receive incremental backups from the master in real time. Thus, the rollback time is reduced almost to the network lag. If the Master fails, you can quickly appoint one of the slaves as the “new Master” and redirect clients to it. In addition, slaves can process requests to read data (SELECTs); this can be used to perform some calculations or reduce the load on the master. MySQL supports replication out of the box, the process is well described by the user

In this article we will look at several practical examples of backing up database recovery using mysqldump. The mysqldump utility is an effective tool for creating a backup copy of a MySQL database. It allows you to create a *.sql file with a collection (dump) of all tables and data of the main database (source).

To back up MyISAM databases, it is better to use the tool mysqlhotcopy, which we will definitely describe in the following articles, since with them it works faster and more efficiently.


By using mysqldump, you can either create a backup copy of local databases or restore them to remote databases. In this article we will look at several practical examples of database recovery backup using mysqldump.

Basic commands for creating a backup and restoring a database MySQL using mysqldump There is:

In these commands:

-u– a parameter that specifies the login used in this case to connect to the database;

-p– a parameter that specifies the user password for this login. If you do not specify a password after this parameter, then after running the command you will need to enter it additionally;

[database name]– name of the database whose backup copy needs to be created;

[backup_database_file_name].sql– the user can specify any convenient name for the database backup file. If you specify the file name as in the provided example, a backup copy of the database will be created in the folder from which the command was launched, namely:
C:\Program Files\MySQL\MySQL Server 5.7\bin

To save a database backup in another folder, before the name of the database backup file in the command, you must specify the path to such a folder. In this case, the commands for creating and restoring a database backup will look like this:

# mysqldump -uroot -pqwerty my_db C:\Users\Valery\Documents\MySQL_Backup\my_db-dump1.sql
# mysql -uroot -pqwerty my_db C:\Users\Valery\Documents\MySQL_Backup\my_db-dump1.sql


How to Backup a MySQL Database

To create a backup copy of one database, just use the standard command described above:

# mysqldump –u[user] –p[user_password] [database_name] [backup_file_name of database] .sql

For example:

# mysqldump -uroot -pqwerty my_db > my_db-dump1.sql

Backup multiple databases

Before backing up multiple databases at once, identify the presence of the databases.

To do this, enter the command show databases(in Workbench)

or # mysqlshow –uroot -p(in the console).


If you need to back up multiple databases at the same time (for example, my_db And test), then to do this you need to run the following command:

# mysqldump -uroot -pqwerty –databases my_db test my_db_test_backup.sql

Backup of all databases

If there is a need to create a backup of all databases in your MySQL profile, this can be done using the parameter –all-databases.

# mysqldump -uroot -pqwerty –all-databases all-databases_backup.sql

Backup a single table

You can also back up an individual database table. In case you need to create a copy of the table wp_commentmeta from database my_db, then the command will look like this:

# mysqldump -uroot -p my_db wp_commentmeta table_ my_db-wp_commentmeta.sql

Note. To view a list of database tables, enter the command:
#mysqlshow –uroot –p my_db


How to restore a MySQL database from a backup

Restore MySQL Database from a backup created by any of the methods described above, you can use one standard method, which is described at the beginning of the article.