Backing up files and database

If you want to back up your important data, there is a few things to consider:

  • your data pack (let's assume it's in /home/otsmanager/forgottenserver)
  • your website files (location: /home/otsmanager/www or /home/otsmanager/www/public_html)
  • your MySQL database dump

Pretty much everything else does not matter - it will be recreated when you purchase a new OTS Hosting Service or run our installation script - depending on which you use.

Backing up files

When it comes to backing up your files, this is simple. You can check out our article on how to [[share files|I-want-to-send-receive-a-file-directory-to-from-my-friend]] to simply download a backup to your PC.

Simply use those two commands:

otsmanager@176-31-89-137:~$ transfer /home/otsmanager/forgottenserver

otsmanager@176-31-89-137:~$ transfer /home/otsmanager/www

Backing up databases

TIP: The server automatically makes MySQL backups and stores them in /var/lib/automysqlbackup/.

In order to transfer your MySQL database, you first need to export it to a file. Assuming your database name is forgottenserver run:

otsmanager@176-31-89-137:~$ mysqldump forgottenserver | gzip > forgottenserver.sql.gz

Now you can transfer it as usual:

otsmanager@176-31-89-137:~$ transfer forgottenserver.sql.gz

Restoring database

In case you need to restore your MySQL database from a backup, first identify which file you want to restore.

Your backups are located in /var/lib/automysqlbackup/ directory, in a subdirectory named after the frequency of rotation (daily, weekly, monthly, etc). The file name includes date and time of the backup.

Note: if you restore a backup, you are restoring a full database. If you want to restore a single table (which may lead to database corruptions), you have to manually inspect the dump file. How to do it is not explained in this article.

For the purpose of this article, we assume the database we want to restore is called forgottenserver.

  1. First, you should take a backup of the existing state of database - just in case you want to go back.

    mysqldump forgottenserver > current-forgottenserver.sql

  2. Secondly, drop the database and create it again - this makes forgottenserver an empty database.

    mysql -e "drop database forgottenserver; create database forgottenserver;"

  3. Finally, restore the database from backup (change the path to point to the backup file you want to restore):

    gunzip -c /var/lib/automysqlbackup/daily/forgottenserver/forgottenserver_2015-12-20_00h50m.Sunday.sql.gz | mysql forgottenserver

You are done! Unless you see some errors, backup is now restored.