Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
96 views
How To Backup PostgreSQL Databases On An Ubuntu VPS - DigitalOcean
Uploaded by
best_wail
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save How To Backup PostgreSQL Databases on an Ubuntu VP... For Later
Download
Save
Save How To Backup PostgreSQL Databases on an Ubuntu VP... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
96 views
How To Backup PostgreSQL Databases On An Ubuntu VPS - DigitalOcean
Uploaded by
best_wail
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save How To Backup PostgreSQL Databases on an Ubuntu VP... For Later
Carousel Previous
Carousel Next
Save
Save How To Backup PostgreSQL Databases on an Ubuntu VP... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 8
Search
Fullscreen
4) Community = TUTORIAL How To Backup PostgreSQL Databases on an Ubuntu VPS Ubuntu PostgreSQL Backups By Justin Ellingwood Posted August 28,2013 @ 381k What is PostgreSQL? PostgreSQL is a modern database management system. It is frequently used to store and manipulate information related to websites and applications. ‘As with any kind of valuable data, itis important to implement a backup scheme to protect against data loss. This guide will cover some practical ways that you can backup your PostgreSQL data. We will be using an Ubuntu 12.04 VPS with PostgreSQL 9.1. Most modern distributions and recent versions of PostgreSQL will operate in a similar way. How to Back Up a PostgreSQL Database Using pg_dump PostgreSQL includes a utility called "pg_dump' that can be used to dump database information into a file for backup purposes. The pg_dump utility is run from the Linux command line. The basic syntax of the command is: pg_dump name_of database > name_of_backup_file The command must be run by a user with privileges to read all of the database information, so it is run as the superuser most of the time.For a real-world example, we can log into the "postgres" user and execute the command on the default database, also called "postgres": sudo su - postgres pe_dump postgres > postgres_db.bak This command is actually a PostgreSQL client program, so it can be run froma remote system as long as that system has access to the database. Ifyou wish to backup a remote system, you can pass the "-h" flag for specifying the remote host, and the "=p" flag to give the remote port: pg_dump -h remote host -p remote_port name_of_database > name_of_backup_file You can also specify a different user using the "-U" option if necessary. The syntax would be: pe_dump -U user_name -h remote host -p remote port name_of database > name_of_backup_file Keep in mind that the same authentication requirements exist for pg_dump as for any other client program. This means that you must ensure that your log in credentials are valid for the systems you are trying to back up. How to Restore Data Dumps from pg_dump with PostgreSQL To restore a backup created by pg_dump, you can redirect the file into psql standard input: psql empty database < backup_file Note: this redirection operation does not create the database in question. This must be done in a separate step prior to running the command. For example, we can create a new database called "restored_database" and then redirect a dump called "database.bak" by issuing these commands:createdb -T template® restored_database psql restored_database < database. bak The empty database should be created using "template0" as the base. Another step that must be performed in order to restore correctly is to recreate any users who own or have grant permissions on objects within the database. For instance, if your database had a table owned by the user "test_user’, you will have to create it on the restoration system prior to importing: createuser test_user psql restored_database < database. bak Dealing with Restoration Errors By default, PostgreSQL will attempt to continue restoring a database, even when it encounters an error along the way. In many cases, this is undesirable for obvious reasons. It can be painful to try to sort out what operations are needed to restore the database to its proper state. We can tell PostgreSQL to stop on any error by typing: psql --set ON_ERROR_STOP-on restored database < backup_file This will cause a PostgreSQL restore operation to halt immediately when an error is encountered. This will still leave you with a crippled database that hasn't been fully restored, but you can now handle errors as they come up instead of dealing with a list of errors at the end. A better option in many situations can be the "-1" (the number one) or "--single- transaction” option: psql -1 restored database < backup file This option performs all of the restoration details in a single transaction.The difference between this option and the "ON_ERROR_STOP" setting is that this will either succeed completely or not import anything This can be a costly trade-off for larger restorations, but in many cases, the benefit of not leaving you with a partially restored database heavily outweighs that cost. How to Backup & Restore All Databases in PostgreSQL To save time, if you would like to backup all of the databases in your system, there is a utility called "pg_dumpall’. They syntax of the command is very similar to the regular pg_dump command, but it does not specify the database. Instead, the command backs up every available database: pg_dumpall > backup_file You can restore the databases by passing the file to psql, with the default database: psql -# backup file postgres Conclusion Backups are an essential component in any kind of data storage plan. Fortunately, PostgreSQL gives you the utilities necessary to effectively backup your important information As with any kind of backup, itis important to test your backups regularly to ensure the copies that are created can be restored correctly. The backups you create are only useful if they can actually be used to recover your system. By Justin Ellingwood By Justin Ellingwood Posted August 28, 2013 © 381kWas this helpful? VHYO Report an issue Related TUTORIAL TUTORIAL How To Install and How To Secure Nginx Configure Postfix on with Let's Encrypt on Ubuntu 20.04 Ubuntu 20.04 Postfix is a popular open- Let's Encryptis a source Mail Transfer Agent Certificate Authority (CA) (MTA) that can be used to that provides an easy way route and deliver email on to obtain and install free TUTORIAL TUTORIAL How To Serve Flask How To Install and Applications with Configure Laravel with Gunicorn and Nginx on Nginx on Ubuntu 20.04 Ubuntu 20.04 L aravel is an open-source In this guide, you will build PHP framework that a Python application using provides a set of tools and the Flask microframework resources to build modernStill looking for an answer? &$8 Aska question Q__ Search for more help 7 Comments eb A B ° Leave a comment... eRe +, arosemenae October 16,2013 this is the script that i use to backup my database, it creates a backup with a timestamp and keeps the latest 14 backups, i run it on a daily cron so this script keeps a 2week daily backup of the database Is -t *.sql | sed -e ‘1,13d" | xargs echo Done at “date +\%V-\%m=\%d_\%T” pg_dump dbname --username=dbuser > “date +\XY-\%m-\%d_\&T° .sql ‘\n" rm Reply Report % rahul.dimri June 30, 2014 HiAll, | got similar requirement in one of my project, Where | need to take back and stored the data on remote directory. Could you please let me know Do | need to modify this above scriptReply Report & Araknor Decemberts 2014 > Found a handy script here: https://gist github.com/matthewlehner/3091458 Looks like someone was copying the automysqlbackup script and making it work for PostgreSQL. Seems to work! Reply Report 2, islammanjurul January 9,206 Hi, can you help to upgrade postgres to newer version. My db is now on 9.4, want to upgrade to 9.5 and to make sure all my existing database, tables, and pg configurations and settings are transferred to newer one. | am looking for a detailed guide Reply Report 2 devmtl123 August 16,2016 When | use psql -f backup_file postgres | got all kinds of errors like these: psql:2016-08-14 @2h5@n_S@_pg-master.bak:15427: psql: 2016-08-14 @2hS@m_S@_pg-master.bak:15435: psql:2016-08-14 @2h5@n_S@_pg-master.bak: psql: 2016-08-14 @2hS@m_S@_pg-master.bal psql: 2016-08-14 @2hS@m_S@_pg-master-bal psql: 2616-08-14 @2hS@m_S@_pg-master.bak:15467: psql: 2016-08-14 @2hS@n_5@_pg-master.bak:15475: psql: 2016-08-14 @2hS@m_5@_pg-master.bal psql: 2016-08-14 @2hS@n_S@_pg-master.bal psql:2016-08-14 @2h50n_5@_pg-master.bak: psql: 2016-08-14 @2hS@m_S@_pg-master.bak:15507: psql:2016-08-14_@2hS@m_S@_pg-master.bak:15515: multiple primary keys for ta relation “accesstokens_token multiple primary keys for ta relation "app_settings key _u multiple primary keys for ta relation “apps_name_unique" multiple primary keys for ta relation “apps_slug_unique" multiple primary keys for ta relation "clients_name_uniqu multiple primary keys for ta relation “clients_slug_uniqu SoI need to manually delete each individual database !! It drives me crazy. How can | force an overwrite ?? I'm using version 9.4.18 within a Docker container.Cheers! Pp Reply Report G Olek September 2018 I'm using Pg_dump if | need to backup PostgreSQL database on Linux, it’s really the best way. But sometimes | have to work with PostgreSQL on Window, and in that case, | use the simple tool to backup Postgres database - PostgreSQL-Backup http://postgresql- backup.com/postgresql-blog/backup-postgres-database . I wish to use PostgreSQL- Backup to backup Postgres databases on Linux. Reply Report +, amayash6777 April 30, 2019 how to download backup file to local computer from digital ocean Reply Report This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License. BECOME A CONTRIBUTOR You get paid; we donate to tech nonprofits.
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6127)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2543)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
20 Best Robot Kits 2019 - From Lego To Arduino - Luca Robotics
PDF
No ratings yet
20 Best Robot Kits 2019 - From Lego To Arduino - Luca Robotics
17 pages
Delphi VirtualTreeView and Tree Structure - Delphi-PRAXiS
PDF
No ratings yet
Delphi VirtualTreeView and Tree Structure - Delphi-PRAXiS
10 pages
Install Firebird On QNAP-NAS
PDF
No ratings yet
Install Firebird On QNAP-NAS
2 pages
Some Studies in Firebird Performance: Paul Reeves Ibphoenix
PDF
No ratings yet
Some Studies in Firebird Performance: Paul Reeves Ibphoenix
43 pages
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Yes Please
From Everand
Yes Please
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
20 Best Robot Kits 2019 - From Lego To Arduino - Luca Robotics
PDF
20 Best Robot Kits 2019 - From Lego To Arduino - Luca Robotics
Delphi VirtualTreeView and Tree Structure - Delphi-PRAXiS
PDF
Delphi VirtualTreeView and Tree Structure - Delphi-PRAXiS
Install Firebird On QNAP-NAS
PDF
Install Firebird On QNAP-NAS
Some Studies in Firebird Performance: Paul Reeves Ibphoenix
PDF
Some Studies in Firebird Performance: Paul Reeves Ibphoenix
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel