Tutorial Overview
This tutorial describes how to restore files, directories, and databases from backups, focusing on both rsync
file backups and mysqldump
database backups.
Prerequisites
- Access to a backup created by
rsync
ormysqldump
.
Steps
Step 1: Restoring Files and Directories with rsync
1. Use rsync to restore a directory from a backup location (replace /backup/documents_backup and /home/user/documents):
sudo rsync -a /backup/documents_backup/ /home/user/documents
- The trailing
/
afterdocuments_backup
is important as it tellsrsync
to copy the contents rather than the directory itself.
2. Verify the Restoration:
- Check the restored files and directories:
ls /home/user/documents
3. Restore Specific Files:
- If only certain files need restoration:
sudo rsync -a /backup/documents_backup/important_file.txt /home/user/documents
Step 2: Restoring a MySQL Database from a mysqldump Backup
1. Log into MySQL:
mysql -u root -p
2. Create the Database to Restore:
- If the database doesn’t exist, create it:
CREATE DATABASE database_name;
3. Restore the Backup:
- Use the following command to restore from the backup file:
mysql -u root -p database_name < /backup/database_name_backup.sql
Step 3: Restore All Databases
1. If a full backup of all databases was made, use:
mysql -u root -p < /backup/all_databases_backup.sql
2. Verify the Restoration:
- Check that the restored data is available:
SHOW DATABASES;
USE database_name;
SHOW TABLES;
Step 4: Restoring Compressed Backups
1. If the .sql backup file is compressed, decompress it first:
gunzip /backup/database_name_backup.sql.gz
2. Restore the Decompressed Backup:
mysql -u root -p database_name < /backup/database_name_backup.sql