User Tools

Site Tools


computing:linux:mysql_backup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
computing:linux:mysql_backup [2016/10/29 16:33]
gcooper
computing:linux:mysql_backup [2018/10/01 14:33] (current)
gcooper
Line 1: Line 1:
 ====== MySQL and PostgreSQL Backup Script ====== ====== MySQL and PostgreSQL Backup Script ======
  
-touch ~/.pgpass +===== Reset Forgotten PostgreSQL Password =====
-$ chmod 0600 ~/.pgpass+
  
 +If necessary, as ''root'':
  
 +<file>
 +sudo su postgres && psql
 +
 +ALTER USER postgres with password 'newpostgresuserpassword';
 +
 +\q
 +
 +exit
 +</file>
 +
 +===== PostgreSQL Password =====
 +
 +For scripts that run as ''root'':
 +
 +<file>
 +touch ~/.pgpass && chmod 0600 ~/.pgpass && vim ~/.pgpass
 +</file>
 +
 +and add:
 +
 +<file>
 +#server:port:database:username:password
 +localhost:*:*:postgres:yourpostgresuserpass
 +</file>
  
 ===== db_backup.sh ===== ===== db_backup.sh =====
Line 23: Line 47:
  
 # Mysql password # Mysql password
-MYSQLPW="bad1egg!!"+MYSQLPW="password"
 # Mysql username # Mysql username
 MYSQLUSER="root" MYSQLUSER="root"
Line 103: Line 127:
 exit exit
 </file> </file>
 +
 +====== Restore A MySQL Backup ======
 +
 +One-liner to restore a gzipped MySQL backup:
 +
 +<file>
 +gunzip < mysql-database-name.sql.gz | mysql -p -h localhost mysql-database-name
 +</file>
 +
 +:!: You will need to enter the database password of the database on 'localhost' being restored to.
computing/linux/mysql_backup.1477780425.txt.gz · Last modified: 2016/10/29 16:33 by gcooper