Advertisement
Guest User

Untitled

a guest
Feb 13th, 2017
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. # Postgres Snippets
  2.  
  3. Backup a django Postgres database
  4. ```
  5. cd /codedata/code/django-study/mysite
  6. # Stop the django surver so database will not be updated
  7. # DBNAME=django_link
  8. DBNAME=databasename
  9. dumpfile=$DBNAME.pg_dump.$(date +%Y-%m-%d-%H:%M:%S).sql
  10. pg_dump $DBNAME > ../databak/$dumpfile
  11. ```
  12.  
  13. ### Create a database
  14. ```
  15. DBNAME=databasename
  16. # dropdb $DBNAME
  17. createdb -U $USER --locale=en_US.utf-8 -E utf-8 -O $USER $DBNAME -T template0
  18.  
  19. # Check database created
  20. psql
  21. greg=# \l
  22. ```
  23.  
  24. ### Restore backup into new database
  25. ```
  26. # check target database
  27. echo $DBNAME
  28. echo $dumpfile
  29. psql $DBNAME < $dumpfile
  30.  
  31. # Check database
  32. psql $DBNAME
  33. linkapp2=# \d
  34.  
  35. # restart django server
  36. ```
  37.  
  38. # MYSQL Snippets
  39.  
  40. Backup a MySQL database
  41. ```
  42. # add a space to start of command to keep command out of bash history
  43. export DBNAME=database_name
  44. export DBUSER=database_user
  45. export PASSWORD=password
  46. export DUMPFILE=$DBNAME.mysql_dump.$(date +%Y-%m-%d-%H:%M:%S).sql
  47. mysqldump -u $DBUSER -p$PASSWORD $DBNAME > $DUMPFILE
  48. ```
  49.  
  50. ### Create a database
  51. tbd
  52.  
  53. ### Restore backup into new database
  54. ```
  55. # check target database
  56. echo $DBNAME
  57. echo $dumpfile
  58. mysql -u root -prootpass $DBNAME < $dumpfile
  59. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement