Example - Back up and restore a cluster
Cloud Service automatically and continuously saves backups of your clusters. You can restore your cluster to any point in the past after the initial backup on cluster creation. That functionality is included in the free trial as well. While that means you don't have to do anything to generate backups, it's always sensible to test your backups.
If you haven't already, create a cluster on EDB Postgres AI Console.
We're going to add a database called "baseball," which we'll populate with some Major League Baseball statistics.
Now you can switch to your new (and empty) baseball database. You're prompted for the edb_admin
password you provided when connecting to the cluster.
Normally you use the log files to determine the moment in time that you want to restore. For the purposes of this demonstration, let's change the prompt to include a timestamp to have an accurate timing of our activities. For convenience, we'll use the (almost) ISO-8601 format that the restore command accepts.
For this demonstration, we're just going to import batter data from the Baseball Databank, which is in CSV form. While it's easy to import the data using PostgreSQL's COPY command, we'll need to first define a table to put that data into. Most of the columns are integers, but there are a few strings to consider as well. You can copy and paste this command into your terminal.
Now we can populate the table from the internet using the most recent data.
Just to prove there's data loaded, let's look at the home run leaders for the 1998 season.
Suppose someone wanted to revise history a bit.
Note the time so we can restore that data later. Verify the data has been changed by rerunning the 1998 home run leader query. Now go ahead and drop the whole table.
You can verify the table is gone by looking at the list of tables.
Restore the cluster using the timestamp before the time you dropped the table.
Optional arguments for the CLI
We're only providing the information we have handy to the restore command: the ID of the cluster, the fact that the cluster is deleted, and the timestamp for the restore point. The CLI will prompt for additional information, such as the password or the region to restore to, and allow you to enter or select from a list as appropriate.
If you know ahead of time the options you'll need, you can provide all of them using parameters, and the command will run non-interactively. The values for the other parameters you don't specify will be inherited from the source cluster.
Check the status of the new cluster from the command line.
Once provisioning is complete, you'll want to grab the new connection information. The hostname changed!
Log in to the new cluster. Be sure to use the new hostname, and use the edb_admin password you provided when restoring the cluster.
Verify that the batters table was restored:
Further reading
Cloud Service CLI reference and Backing up and restoring in the full version documentation.
- On this page
- Further reading
Could this page be better? Report a problem or suggest an addition!