Skip to main content

Download your data from Otax Web Host

How to migrate your data from Otax shared hosting to an another service

Where is my data?

Your association's data is in three places

  • Your user's home folder /home/|association|
  • Your www-folder /www/|association|
  • Your users MariaDB database on the server

The www-folder is symbolically linked to your folder under /home/|association|/www-data. A symbolic link is a file that points to an another file or folder.

Please note that most file copy or archiving tools do not follow symbolic links by default.

Finding home

The user's home folder is commonly abbreviated to the '~' symbol in Linux systems. Instead of writing /home/|association|/file.txt you can write ~/file.txt.

Back up the data

Run these commands remotely on the Otax server to back up all your data to to a folder called backup in your home folder. Once you have backed up the data, you can then conveniently download that folder to your computer, or any computer that you wish to migrate your data to.

You can login to Otax with your association's credentials using a SSH-client. A SSH client is installed by default on Windows, macOS and most (if not all) distributions of Linux.

To login to your association's account you will need to know the name of your associations Otax-account and have a SSH identity file that has a permission to log in to the account.

Login to Otax with SSH
ssh |association|@otax.fi

Home folder and WWW-folder

# Move to home directory
cd ~
# Create the backup directory
mkdir backup
# Back up the home folder to "~/backup/home.tar.gz".
# The backup folder is excluded from the backup so that we don't get recursive backups.
tar --create --exclude=backup/* --gzip --file=backup/$(whoami)-home.tar.gz .
# Back up the www-folder to "~/backup/www.tar.gz"
tar --create --gzip --file=backup/$(whoami)-www.tar.gz --directory=/var/www/home/$(whoami) .

MariaDB-database

The name of the database is the same as your association's name.

Dump the database to the backup folder
# If you have unix socket authentication enabled for the user
#you don't need to specify the user or the password.
mysqldump --single-transaction |database_name| | gzip > ~/backup/$(whoami)-db.sql.gz
# Likely you will need to specify the user and the password.
# Where you can find them depends a bit on when and how your account was created.
# If you have a 'mysql_password.cnf' file in your home folder, you can use that to get the password.
mysqldump --single-transaction --defaults-extra-file=mysql_password.cnf |database_name| | gzip > ~/backup/$(whoami)-db.sql.gz
# Otherwise you will have to find the password from the home folder of your user and provide it to the command.
# Generally the credentials are stored in some file starting with 'mysql'
mysqldump --single-transaction --user=|user| --password=|password| |database_name| | gzip > ~/backup/$(whoami)-db.sql.gz

If you are unable to get the credentials of your database, you can contact AYY IT.

Download the backups

Run these commands locally on the computer you want to download the backups to.

Download the backups with SCP
scp |association|@otax.ayy.fi:~/backup/* .
Download the backup folder interactively with SFTP
# Start SFTP session
sftp |association|@otax.fi

# Navigate to the backup folder
sftp> cd backup

# See that the files are present
sftp> ls

# Download all the files in the folder
sftp> get .

# Exit the sftp session
sftp> exit

The files should now be on your local computer in the directory you ran these commands from.

Recovering your data

Once you have downloaded the backups, you can move the files to your new server and restore them.

Extracting the backup files

The backup files are compressed with gzip. You can extract them with the following commands.

Extract the backup files
# Extract the tar files with the following command
tar --extract --gzip --file=|filename| --directory=|destination|
# Example for the home folder
tar --extract --gzip --file=backup/|association|-home.tar.gz --directory=~/
# Example for the www-folder
tar --extract --gzip --file=backup/|association|-www.tar.gz --directory=~/www-data
# Extract the database
gunzip backup/|association|-db.sql.gz

Replace |filename| with the name of the backup file you want to extract. Replace |destination| with the folder you want to extract the file to. You can use tab-completion to help you with this by pressing the tab key to autocomplete the filename or the target directory.

The gunzip command will extract the file and remove the .gz extension from the file. The database dump is a single file which means that it can be extracted in-place, meaning that the .gz file with the extracted .sql file.

Loading the database dump to MySQL or MariaDB

MySQL vs MariaDB - what's the difference?

MySQL and MariaDB are both relational database management systems (RDBMS) that use the same query language. They are generally interchangeable with each other. For example, WordPress supports both MySQL and MariaDB and you can import a database dump from one to the other.

You can use both MariaDB and MySQL through the same command line client 'mysql'.

You can load the database dump to your new server with the following command.

Load the database dump
mysql |database| < backup/|association|-db.sql
# Alternatively, if the database dump is compressed
gunzip --stdout backup/|association|-db.sql.gz | mysql |database|
# You might also need to specify the user and the password
mysql --user=|user| --password=|password| |database| < backup/|association|-db.sql

Replace |database| with the name of the database you want to load the dump to.

You will need to create the database and the user for the database before you can load the dump. Your service provider might have a web interface for this, or you can use the command line.

Generally there are two ways to authenticate to a MySQL server, Unix socket authentication and password authentication.

Unix socket authentication is a method of authentication that uses the operating system to authenticate a user. The server checks database permissions based on the user that is running the process.

Password authentication, on the other hand, is a method of authentication that requires a password to connect to the database. The server asks the user for the password before allowing the user to connect.

In summary, Unix socket authentication uses the operating system's built in user management to authenticate a user, while password authentication requires a user to provide a password to authenticate.

How to create a database and a user from the command line

First open a mysql session with the following command.

Open a MySQL/MariaDB session
mysql

Then run the following commands to create the database and the user.

Create the database and the user
-- Create the database
CREATE DATABASE |database|;
-- Create a user for the database with a password
CREATE USER '|user|'@'localhost' IDENTIFIED BY '|password|';
-- Alternatively, create a user for the database with unix socket authentication
CREATE USER '|user|'@'localhost' IDENTIFIED WITH unix_socket;
-- Grant the user access to the database
GRANT ALL PRIVILEGES ON |database|.* TO '|user|'@'localhost';
-- Flush the privileges to apply the changes
FLUSH PRIVILEGES;

Again, replace |database|, |user| and |password| with the name of the database, username and the password for the user that you want to create.

Note that by using @'localhost' you are limiting the user to only be able to connect to the database from the same server. If you want to allow the user to connect from anywhere, you can use @'%' instead. However, it is generally preferred to limit the user to only be able to connect from the same server, as it is more secure.

If you need to connect to the database remotely, you can use SSH-tunneling to connect to the database.

If you want to change the password of an existing user or their authentication method, you can use ALTER USER.

Change the password or the authentication method of an existing user
-- Change the password of an existing user and set the authentication method to password authentication
ALTER USER '|user|'@'localhost' IDENTIFIED BY '|password|';
-- Change the authentication method of an existing user to unix socket authentication
ALTER USER '|user|'@'localhost' IDENTIFIED WITH unix_socket;

Here are some useful commands for managing users and databases.

Useful commands for managing users and databases
-- List all users
SELECT user, host FROM mysql.user;
-- List all databases
SHOW DATABASES;
-- List all privileges for a user
SHOW GRANTS FOR '|user|'@'localhost';