ServerBackup

Backup

Database backup

1. (optional for butch mode)

create config file in home folder

sudo nano ~/.my.cnf

in config file write user name and password

[mysqldump]
user=mysqluser
password=secret

protect file

sudo chmod 600 ~/.my.cnf

2. Save database to file

sudo mysqldump -u root db_name > /var/www/mysql/file_name.sql

In case of batch mode launch script for saving database

bash /var/www/db_backup.sh

Files backup

tar -cvpzf /media/extdrive/sites_backups/backup_07-02-2021.tar.gz /var/www

where

  • c - create a new backup archive
  • v - verbose mode, tar will print what it's doing to the screen
  • p - preserves the permissions of the files put in the archive for restoration later
  • z - compress the backup file with 'gzip' to make it smaller
  • f <filename> - specifies where to store the backup, backup.tar.gz is the filename used in this example. It will be stored in the current working directory, the one you set when you used the cd command

Recovery

Database recovery

1) Login to mysql and create new database

mysql -u username -p


CREATE DATABASE database_name;
exit

2) Import

mysql -u username -p db_name < file_name.sql

Files recovery

tar -zxpv /media/extdrive/sites_backups/backup_07-02-2021.tar.gz -C /var/www
Page last modified on May 03, 2021, at 06:55 AM
Powered by PmWiki