Xz -dc proget-backup- |īecause we compressed the SQL script in the previous command, we need to decompress it before we can restore the backup. This will be placed in the current directory when you run the command. The compressed SQL script is currently being written on the standard output, so we redirect it to a file with a name like proget-backup. However, the default compression level should be good enough in nearly every case. 9 makes xz use much more memory, and -e makes xz use much more CPU power. To get even better compression, the -9 and/or -e options can be specified. This is optional, and other commands can be used in place of xz, such as gzip and bzip2. We run the SQL script through a compression program (in this case, xz) to reduce the amount of storage space taken by the backup and to reduce the time it takes to transfer the backup over the network. This makes it easier to restore in one step. –clean tells pg_dump to start the SQL script by dropping the data that is currently in the database. –create tells pg_dump to include tables, views, and functions in the backup, not just the data contained in the tables. It can also convert to some other formats, but we aren’t going to use those right now. Pg_dump is the PostgreSQL database backup utility. If you created the container with a different name, substitute it here. This is the name of the Docker container running PostgreSQL. We want to run the command as the postgres user because the docker exec command defaults to using the root user and the root user does not have access to the database. This runs a command inside a Docker container. Xz -dc proget-backup- | docker exec -i -u postgres proget-postgres psql –set ON_ERROR_STOP=on –single-transaction The commands below will work as-is, but if you want to know what each piece does, continue reading.ĭocker exec -u postgres proget-postgres pg_dump -Cc | xz > proget-backup-$(date -u +%Y-%m-%d).sql.xz Install in minutes on Windows or Linux/Docker, and start using today! Backup and Restoreīacking up a PostgreSQL database uses the pg_dump command, and restoring it uses the psql command. ProGet is a free private Docker registry and package server that you host on your own infrastructure. This article will give you some commands to use for this. Sometimes, you’ll need to access a PostgreSQL database directly inside of a Docker Container.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |