Database Backup and Restore

PostgreSQL

Table Import and Export:

Export: psql --dbname=trusteeze_live_v1 --username=habib --host=localhost -c "COPY (SELECT * FROM templates) TO stdout DELIMITER ',' CSV HEADER" > export.csv


Method - 1:

pg_dump -U user_name -h remote_host -p remote_port name_of_database > name_of_backup_file

example: cd Desktop

pg_dump -U postgres db_development > my_s_bag


Method - 2:

psql -h localhost -U habib -W -d ecom_developmentx < staging_dump07022021.sql


Method - 3:

pg_restore --no-privileges --no-owner --if-exists -1 -c -U habib -d ecom_development prod_21_04_2021.dump


Method - 4:

backup: pg_dump -U username -f backup.sql database_name

restore: psql -d database_name -f backup.sql


Method - 5:

final work:

backup: pg_dump -h localhost -U postgres -W -d db_prod > db_prod_v2.sql


Method - 6:

restore: psql -h localhost -U postgres -W -d prod_db_v3 < production_v3.sql

MySQL

Method - 1:

mysqldump -u root projdb_live > dbfile.sql

mysql -u root -p proj_development < projdb.sql