Skip to content

Instantly share code, notes, and snippets.

@Furqanameen
Last active March 19, 2024 07:04
Show Gist options
  • Save Furqanameen/0f835bc74ea17b34218760fc3ad2c8f9 to your computer and use it in GitHub Desktop.
Save Furqanameen/0f835bc74ea17b34218760fc3ad2c8f9 to your computer and use it in GitHub Desktop.
Restore dump on the remote machine -- DB dump on the remote machine. download a complete directory using the -r switch along with SCP
scp deploy@ip:/home/deploy/ph_tax_rebats_staging_h2_29_agust_2023.sql /Users/brooksdaleltd/Documents
Downloading anything from the server run below command
Step 1: Open a new terminal in Linux/UNIX or command prompt in Windows.
Step 2: To download a complete directory using the -r switch along with SCP command.
scp deploy@IP:/home/deploy/filename.sql /Users/brooksdaleltd/Documents
if you want to download directory istead of file then use -r like below
scp -r deploy@IP:/home/deploy/filename.sql /Users/brooksdaleltd/Documents
Uploading anything to the server run below command
scp /Users/brooksdaleltd/Documents/tax_crm_ph_staging_v1_29_agust_2023.sql deploy@ip:/home/deploy/
if you want to Upload directory istead of file then use -r like below
scp -r /Users/brooksdaleltd/Documents/tax_crm_ph_staging_v1_29_agust_2023.sql deploy@ip:/home/deploy/
For taking Dump from the server of DBs
pg_dump -Fc db_name -U db_user_name -h localhost/ip > path.sql
Restore Postgres database using pg_restore over SSH
pg_restore -U db_user_name -d db_name -h server_ip -p 5432 -W /home/deploy/filename.sql
or
Simply in case don't require user name pass
pg_restore -d db_name filepath
For taking Postgresql dumo using URL..
pg_dump "postgresql://....."
if want to save into local directory then add like below
pg_dump "postgresql://....." > filename
# if you face this issue below issue while restroing database from one server to other server
## pg_restore: error: input file appears to be a text format dump. Please use psql.
https://docs.digitalocean.com/products/databases/postgresql/how-to/import-databases/
# Like below command
psql -d <your_connection_URI> < <path/to/your_dump_file.pgsql>
Also here is solution to restore text format database below command....
psql -U username -d db_name -h localhost -p 5432 -f db_name_that_need_to_import.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment