PostgreSQL - pg_dump creating backup with bzip2 compression
Colleagues hello to all.
In continuation of the last article on creating a backup of a PostgreSQL database using the pg_dump utility, today we will talk about how a backup can be compressed using Linux tools. It is possible and even necessary to compress a backup because it can take up a lot of space on your disk. One downside to compressing a backup is that it takes a little longer to create this copy than you did with a regular backup. Compression of the backup will be done by Linux tools, namely a program called bzip2.
Previous article: Creating a PostgreSQL backup - pg_dump
Article content:
- Installing the bzip2 package.
- Examples of backing up a database using compression.
1. Installing the bzip2 package.
You can install the bzip2 package using the yum install package manager. Let's do it.
$. yum install bzip2 -y
I installed this package before, so the server tells me that bzip2 is already installed.
2. Examples creating a database backup using compression.
2.1. A simple demo database backup with compression.
$. pg_dump --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2
2.2. Creating a backup copy under another user and asking for a password for authorization using compression.
$. pg_dump -U postgres -W --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2
2.3. Perform a database backup on a remote server using compression.
$. pg_dump -h 192.168.4.10 --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2
2.4. Back up only the database structure without data using compression.
$. pg_dump --schema-only --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2
2.5. Back up only the data without the structure itself using compression.
$. pg_dump --data-only --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2
2.6. Enable verbose mode when performing backup with compression applied.
$. pg_dump --verbose --data-only --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2
Thank you all, I hope that my article helped you in some way.