of postgresql mysql instance code
- 2021-01-22 08:21:35
- OfStack
posgresql backup/restore
1. Backup
DATE=`date +%Y%m%d-%H%M`
BACK_DATA=xxapp-data-${DATE}.out # Set the name of the backup file here , The date was added to prevent duplication
docker exec pg-db pg_dumpall -U postgres > ${BACK_DATA} # pg-db It's a database docker The name of the
2. Restore
docker cp ${BACK_DATA} pg-db:/tmp
docker exec pg-db psql -U postgres -f /tmp/${BACK_DATA} postgres
mysql backup/restore
1. Backup
DATE=`date +%Y%m%d-%H%M`
BACK_DATA=xxapp-data-${DATE}.sql
# mysql-db It's a database docker The name of the , xxxpwd is root The user password , app-db Is the name of the data to back up
docker exec mysql-db mysqldump -uroot -pxxxpwd --databases app-db > ${BACK_DATA}
2. Restores the following ${BACK_DATA} to be replaced with the actual generated file name
docker cp ${BACK_DATA} mysql-db:/tmp
docker exec -it mysql-db mysql -uroot -pxxxpwd
mysql> source /tmp/${BACK_DATA}.sql
mysql> \q
Bye
supplement
postgresql backs up all databases, mysql backs up one database.
conclusion