Introduction
One recurrent task for database administrators is creating and applying back ups. In this tutorial you will learn how to do this task in a RethinkDB environment.
Requeriments
- A running installation of RethinkdB.
- The python package
rethinkdb
installed to your machine withpip
. Theimport
tool is bundled in that package. It is recommended to use the Python 3 version package, as Python 2 is reaching its end of life soon.
Setting up your data
Before creating a backup it is important to setting up the RethinkDB server, just do this steps quickly:
- Open your Web Panel, it is located at
localhost:8080
- Go to the
Tables
section and add a database namedFinancialXchanges
. - In the database
FinancialXchanges
create a table namedDollar
Now go to the Data Explorer
section and run the following query:
r.db('FinancialXchanges').table('Dollar').insert( [
{
"week": 26, "id": 1, "cad": 1.28837, "jpy": 109.89
},
{
"week": 27, "id": 2, "cad": 1.30979, "jpy": 109.89
},
{
"week": 28, "id": 3, "cad": 1.25588, "jpy": 106.751
},
{
"week": 29, "id": 4, "cad": 1.2483, "jpy": 104.709
},
{
"week": 30, "id": 5, "cad": 1.27785, "jpy": 108.165
},
{
"week": 31, "id": 6, "cad": 1.27459, "jpy": 107.137
},
{
"week": 32, "id": 7, "cad": 1.26657, "jpy": 108.987
}
] )
Now you have the required data to follow this tutorial
Doing a backup
The command to create a backup is dump
, by default it does a backup of all the server. To limit its scope use the -e
option, you can choose the name of the backup with the -f
option:
rethinkdb dump -e FinancialXchanges.Dollar -f backup1.tar.gz
Such file will be stored in your actual folder in your terminal session, you can ls
to see your backup:
YOUR_USER@YOUR_DOMAIN:~# ls
backup1.tar.gz
After this go to your Web Panel and erase the FinancialXchanges
database because you are going to restore in the next section.
Restoring a backup
The tool to restore a backup is restore
. Restore is a powerful tool that let us apply backups over secure tunnels for example or even point to a specific database and table. In your case you only backed up one simple database so you can run the clean command without any extra options:
rethinkdb restore backup1.tar.gz
RethinkDB will tell you the amount of data imported to your server.
To settle things up, run this query in the Data Explorer
section in the Web panel to list the contents of your restored table and database:
r.db('FinancialXchanges').table('Dollar')
You should be able to see the original data that you created steps before.
Conclusion
As you saw managing back ups in RethinkDb is fairly easy. After this tutorial it is recommended to play with the different options of both dump
and retore
commands, so you can understand the different options that those command can offer to you.
Top comments (0)