RESTORE

Restore data from a binary backup file.

Syntax

Local Restore

RESTORE [DATABASE] db_name FROM "backup_path" [WITH {SYNC | ASYNC} REPLICATION]

S3 Restore

RESTORE [DATABASE] db_name FROM S3 "bucket/path" [CONFIG configuration_json] CREDENTIALS credentials_json [WITH {SYNC | ASYNC} REPLICATION]

configuration_json:
'{"region":"your_region"}'

credentials_json:
'{"aws_access_key_id": "replace_with_your_access_key_id",
  "aws_secret_access_key": "replace_with_your_secret_access_key",
  ["aws_session_token": "replace_with_your_temp_session_token",]
  ["role_arn":"replace_with_your_role_arn"]
}'

Azure blobs Restore

RESTORE [DATABASE] db_name FROM AZURE "container/blob-prefix" CREDENTIALS credentials_json [WITH {SYNC | ASYNC} REPLICATION]

credentials json:
'{"account_name": "your_account_name_here",
  "account_key": "your_account_key_here"
}'

Remarks

  • db_name is the name of the MemSQL database to restore to.
  • If you wish to restore the backup of one database into a differently-named database, you can do so by specifying the full path to the old database’s .backup file in backup_path for local backups or path for S3 or prefix-key for Azure blobs. For example, you can do BACKUP DATABASE db TO './path/' followed by RESTORE DATABASE newdb FROM './path/db.backup'. See the Examples section for examples.
  • The RESTORE command replays a binary backup file in the same manner in which MemSQL recovers a database snapshot during startup.
  • WITH {SYNC | ASYNC} REPLICATION controls whether replication in high availability will be done synchronously or asynchronously. The default mode is ASYNC. The default replication mode can be changed by changign the system variable replication_sync). Partitions replicated synchronously will ensure a transaction has reached all slaves before acknowledging the transaction as committed to the user client. While providing stronger consistency guarantees, this can negatively impact write performance. For more information, see Managing High Availability.
  • A RESTORE operation temporarily puts the database being restored into the recovering snapshot state. A database in this state cannot be queried. When the RESTORE command finishes, it puts the database into the online state. (see the Database topic for more information).
  • This command must be run on the master aggregator node (see Node Requirements for MemSQL Commands).

Local Restore Remarks

  • backup_path is the path used in BACKUP .
  • The path backup_path needs to be accessible by the memsqld process. Paths are resolved relative to the memsqlbin/data directory.

S3 Restore Remarks

  • aws_session_token is optional. This is only needed if your AWS account uses the AWS Security Token Service.
  • role_arn is optional. This is only needed if your AWS security is setup to require a role.

Azure Restore Remarks

  • The time limit given to download a file from Azure is 30 minutes. This should be sufficient for most files at most download speeds. If that is not sufficient to download a file, you may get an error saying “truncated tar archive”, in which case you may want to check your connection and retry the operation.

Example

Local Restore

The following example restores from the /var/lib/memsql/data/ directory.

RESTORE DATABASE memsql_demo FROM "./";

S3 Restore

The following example restores from an S3 bucket.

RESTORE DATABASE memsql_demo FROM S3 "backup_bucket/backups/6_1_2018" CONFIG '{"region":"us-east-1"}' CREDENTIALS '{"aws_access_key_id":"replace_with_your_access_key_id","aws_secret_access_key":"replace_with_your_secret_access_key"}';

The following example restores a database(memsql_demo) from an S3 bucket to a database with a different name(new_memsql_demo).

RESTORE DATABASE new_memsql_demo FROM S3 "backup_bucket/backups/6_1_2018/memsql_demo.backup" CONFIG '{"region":"us-east-1"}' CREDENTIALS '{"aws_access_key_id":"replace_with_your_access_key_id","aws_secret_access_key":"replace_with_your_secret_access_key"}';

Azure Restore

The following example restores from an Azure Container.

RESTORE DATABASE memsql_demo FROM AZURE "backup_container/backups/6_1_2018" CREDENTIALS '{"account_name":"your_account_name_here","account_key": "your_account_key_here"}';

The following example restores a database(memsql_demo) from an Azure container to a database with a different name(new_memsql_demo).

RESTORE DATABASE new_memsql_demo FROM AZURE "backup_container/backups/6_1_2018/memsql_demo.backup" CREDENTIALS '{"account_name":"your_account_name_here","account_key": "your_account_key_here"}';

Common Errors

A common error is giving incorrect paths to the backup files to restore command. The path that you give to the RESTORE command should match the path that you gave to the BACKUP command, unless you are restoring to a database with a different name in S3 or Azure restore, in which case, /old_database_name.backup should be appended to your restore path.

Was this article useful?