Restore data
To restore your YugabyteDB databases that were backed up using the ysql_dump
and ysql_dumpall
backup utilities, you can use the ysqlsh
to restore one or all databases.
Restore databases using ysqlsh \i
To restore databases using the ysqlsh
shell:
- Open the
ysqlsh
from the YugabyteDB home directory.
$ ./bin/ysqlsh
ysqlsh (11.2-YB-2.0.9.0-b0)
Type "help" for help.
yugabyte=#
- At the
ysqlsh
shell prompt, run the following\i
command:
yugabyte=# \i <db-sql-script>
- db-sql-script: the SQL script file dumped using
ysql_dump
orysql_dumpall
.
For details about using this command, see \i
in the ysqlsh
documentation.
Note
To reduce security risks, SQL script files created usingysql_dump
include SELECT pg_catalog.set_config('search_path', '', false);
to set the search_path
to an empty string. As a result, when you restore a database from the ysqlsh
shell, running the \d
command returns "Did not find any relations." To see the restored database, set the search_path
again to expected schema to see the restored database.
Restore databases using ysqlsh -f
To restore one database using ysqlsh
on the command line, open a command line window and run the following command. The ysqlsh -f
command will read the SQL statements from the specified file and
$ ysqlsh -f <db-sql-script>
- db-sql-script: the SQL script file dumped using
ysql_dump
orysql_dumpall
.
For details about using this command, see -f, -file
in the ysqlsh
documentation.