Recovery instructions updated and made sure it also works for databases with a dash in the name
This commit is contained in:
parent
4c576d74e3
commit
70704f9702
24
README.md
24
README.md
|
@ -63,13 +63,23 @@ This will add a cronjob to root which will run this script daily at 0:10 am. Adj
|
|||
|
||||
## Recover database ##
|
||||
|
||||
Assuming you want to restore mytestdb from your backups made on 20190121-1540:
|
||||
Assuming you want to restore my-testdb from your backups made on 20211012-0010, define variables:
|
||||
```
|
||||
DB='my-testdb'
|
||||
NEWDB='my-testdb'
|
||||
BACKUPDIR='/var/backup/mysql/20211012-0010'
|
||||
```
|
||||
|
||||
Make sure you have a backup of the current database which will be replaced:
|
||||
```
|
||||
DB='mytestdb'
|
||||
BACKUPDIR='/var/backup/mysql/20190121-1540'
|
||||
sudo mysqldump ${DB} > /root/${DB}-$(date +%Y%m%d).sql
|
||||
sudo mysql -e "DROP DATABASE ${DB}"
|
||||
sudo mysql -e "CREATE DATABASE ${DB}"
|
||||
for table in ${BACKUPDIR}/${DB}/*; do gunzip -c $table | sudo mysql ${DB}; done
|
||||
sudo mysqldump ${NEWDB} > /root/${NEWDB}-$(date +%Y%m%d).sql
|
||||
```
|
||||
|
||||
And now the actual recovery (Need to be in the same session! Do not enter this in another SSH window / terminal):
|
||||
```
|
||||
sudo mysql -e 'DROP DATABASE IF EXISTS `'${NEWDB}'`'
|
||||
sudo mysql -e 'CREATE DATABASE `'${NEWDB}'`'
|
||||
for table in ${BACKUPDIR}/${DB}/*; do gunzip -c $table | sudo mysql ${NEWDB}; done
|
||||
```
|
||||
|
||||
You can change NEWDB to any other name if you wish to restore to an alternate database name!
|
Loading…
Reference in New Issue