SlideShare une entreprise Scribd logo
1  sur  19
Hệ quản trị cơ sở dữ liệu

Backup and Restore Data
Dư Phương Hạnh
Bộ môn Hệ thống thông tin
Khoa CNTT, trường Đại học Công nghệ
Đại học Quốc gia Hanoi
hanhdp@vnu.edu.vn
Outline
 Using mysqldump utility to back up tables in a
single or multiple databases.
 Using backup files with mysql monitor to restore
databases or tables.
 Using binary logs to update restored databases.
 Using various mysqldump Options.

Read more at:
http://mysql-tools.com/en/backup-restore-data-mysql.htm
2

Hệ quản trị CSDL @ BM HTTT
Introduce
 Despite the steps you take to secure and protect your
databases, events such as power failures, natural
disasters, and equipment failure can lead to the corruption
and loss of data.
 Ensure that MySQL databases are backed up regularly
should be part of any maintenance routine.
 These backup files will contain the database and table
definitions necessary to re-create your database structure
as well as the instructions necessary to repopulate your
tables.
3

Hệ quản trị CSDL @ BM HTTT
Introduce
 Using these backup files, you can recover your data to the
state it was in at the time you performed the last backup.
Further, you can use the binary log files to recover your data
to post-backup current state.
 The mysqldump program is the primary method in MySQL
for backing up tables and databases and it can back up
individual databases, tables in those databases, or multiple
databases. When you run mysqldump, the utility creates a
text file that contains the SQL statements necessary to
create your database and tables safely and add data to
those tables.
4

Hệ quản trị CSDL @ BM HTTT
Usage of mysqldump utility
 It is possible to back up databases simply by
copying the data directory to a backup location. This
method has several limitations, though.
– if data is being accessed and updated during file copy,
you might be copying tables that are in an inconsistent
state.
– file-level copying may help MyISAM tables but InnoDB
tables can be more complicated at file level.

5

Hệ quản trị CSDL @ BM HTTT
Using mysqldump
Syntax:
mysqldump [options] dbname [tables]
mysqldump [options] --databases [moreoptions]
dbname1 [dbname2 ...]
mysqldump [options] --all-databases [moreoptions]

6

Hệ quản trị CSDL @ BM HTTT
Using mysqldump
Options:
--no-create-info: Creates no CREATE TABLE
commands, but only the INSERT commands.
--no-data : Creates no INSERT commands (but only
CREATE TABLE commands in order to restore the
database schema).

7

Hệ quản trị CSDL @ BM HTTT
Set Variables
 MySQL saves some system values in user-defined
variables to restore the original system settings
should they be changed by any of the statements
while executing the backup file
 thereby ensuring that your environment is left in the
same state after the restore via execution of the
statements in the backup file.

8

Hệ quản trị CSDL @ BM HTTT
Set Variables
/*!40101 SET
@OLD_CHARACTER_SET_CLIENT=CHARACTER_SET_CLIENT */;
/*!40101 SET
CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

SET statements begin with the /*! symbols and end with the */
symbols. The symbols ensure the statements are executed by
MySQL but ignored if they are executed in another database
management system
The number followed those symbols represents a MySQL
server version.
9

Hệ quản trị CSDL @ BM HTTT
Flush Logs
 Binary log files allow you to restore your database
fully. The option --flush-logs flushes your log files
and a new binary log file is created.
 By flushing the logs, you get an exact starting point
for using the binary logs when refreshing your
restored database. It is recommended that you use
the --flush- logs option whenever you back up your
data.
10

Hệ quản trị CSDL @ BM HTTT
Examples
 Mysqldump –u root –pa sakila >
D:ProgramsEasyPHPtmpsakila1.sql
 mysqldump --flush-logs -u root -pa sakila >
D:ProgramsEasyPHPtmpsakila1.sql
 mysqldump –u root -pa -X sakila actor >
D:ProgramsEasyPHPtmpactor1.xml
 mysqldump --all-databases >
D:ProgramsEasyPHPtmpall_db.sql;
11

Hệ quản trị CSDL @ BM HTTT
Restore Data
 If you have backed up your files regularly and
enabled binary logging, restoring your database
consists of two steps:
– Use the mysql monitor to execute the backup script to
reload a MySQL database.
– Use the appropriate binary logs to update the database.

 These two steps restore a database to the point of
database errors, thus preventing any significant
data loss in case of a faulure or a disaster.
12

Hệ quản trị CSDL @ BM HTTT
Restore Data
 If you are restoring data from a backup file that does
not include a database definition, the database
must exist before restoring.
CREATE DATABASE sakila1;
Use sakila1;
Source D:ProgramsEasyPHPtmpsakila1.sql
or
Mysql –u root –pa test<
13

D:ProgramsEasyPHPtmpsakila1.sql
Hệ quản trị CSDL @ BM HTTT
Update the Restored db From Binary Log
Files
 Once database is reloaded, the data is only as
current as your last backup, which is where binary
logging comes in.
 After you reload your database into your system,
you will most likely want to get the database to its
most current state since it was backed up. You will
use binary logs which track all data modifications
that occur in your databases.
14

Hệ quản trị CSDL @ BM HTTT
Update the Restored db From Binary Log
Files

 MySQL provides two methods for applying updates
from a binary log:
– restoring data directly from the binary log file
– exporting binary log data to a text file and then restoring it
from that file.

 You must have binary logging enabled on your
system to be able to use it to update a restored
database, covered in other lessons.

15

Hệ quản trị CSDL @ BM HTTT
Restoring Data Directly From a Binary
Log
 Mysqld --log-bin

 mysqlbinlog “D:ProgramsEasyPHPmysqldata
HN-bin.000001”
 mysqlbinlog
"D:ProgramsEasyPHPmysqldataHN-bin.000001"
> D:ProgramsEasyPHPmysqldatalog.txt
 mysqlbinlog
"D:ProgramsEasyPHPmysqldataHN-bin.000005"
|mysql -u root –p --one-database sakila1
16

Hệ quản trị CSDL @ BM HTTT
Restoring Binary Log Data From a Text
File
 You can sort through the text file to remove any
statements that you don't want to execute.
 The larger the log file, the more difficult this process
can be, but there might be times when this is the
only way you can ensure that your database is fully
restored.
 After you're satisfied that the text file contains only
the correct statements, you can use the mysql client
utility to execute the statements.
17

Hệ quản trị CSDL @ BM HTTT
Restoring Binary Log Data From a Text
File
 Mysqlbinlog “D:ProgramsEasyPHPmysqldata HNbin.000001” > HN-bin000001.txt
 After editing the text file as necessary, execute the
statements in the text file.
 Mysql -u root –p –one-database < HN-bin000001.txt

18

Hệ quản trị CSDL @ BM HTTT
Exercise
 Tạo CSDL test
 Tạo bảng bảng table1(ID int, Text text);
 Bật chế độ log-bin
 Chèn dữ liệu vào bảng.
 Backup test.
 Xoá một bản ghi trong table1.
 Khôi phục lại test từ file backup.
 Sử dụng logs để khôi phục table1 về trạng thái gần
19

nhất (dùng 2 cách).
Hệ quản trị CSDL @ BM HTTT

Contenu connexe

Tendances

database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recoverysdrhr
 
S3 l7 db2 storage model
S3 l7   db2 storage modelS3 l7   db2 storage model
S3 l7 db2 storage modelMohammad Khan
 
DB2UDB_the_Basics Day 5
DB2UDB_the_Basics Day 5DB2UDB_the_Basics Day 5
DB2UDB_the_Basics Day 5Pranav Prakash
 
Database recovery techniques
Database recovery techniquesDatabase recovery techniques
Database recovery techniquespusp220
 
DB2UDB_the_Basics Day 3
DB2UDB_the_Basics Day 3DB2UDB_the_Basics Day 3
DB2UDB_the_Basics Day 3Pranav Prakash
 
Memory management in oracle
Memory management in oracleMemory management in oracle
Memory management in oracleDavin Abraham
 
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1sunildupakuntla
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory ManagementRahul Jamwal
 
Backup and recovery in oracle
Backup and recovery in oracleBackup and recovery in oracle
Backup and recovery in oraclesadegh salehi
 
Recovery Techniques and Need of Recovery
Recovery Techniques and   Need of RecoveryRecovery Techniques and   Need of Recovery
Recovery Techniques and Need of RecoveryPooja Dixit
 
Introduction of Memory Management
Introduction of Memory Management Introduction of Memory Management
Introduction of Memory Management Maitree Patel
 
Understanding memory management
Understanding memory managementUnderstanding memory management
Understanding memory managementGokul Vasan
 
Process & Mutlithreading
Process & MutlithreadingProcess & Mutlithreading
Process & MutlithreadingRahul Jamwal
 
BACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMSBACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMSBaivabiNayak
 
SHADOW PAGING and BUFFER MANAGEMENT
SHADOW PAGING and BUFFER MANAGEMENTSHADOW PAGING and BUFFER MANAGEMENT
SHADOW PAGING and BUFFER MANAGEMENTramya marichamy
 

Tendances (20)

database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recovery
 
S3 l7 db2 storage model
S3 l7   db2 storage modelS3 l7   db2 storage model
S3 l7 db2 storage model
 
DB2UDB_the_Basics Day 5
DB2UDB_the_Basics Day 5DB2UDB_the_Basics Day 5
DB2UDB_the_Basics Day 5
 
Database recovery techniques
Database recovery techniquesDatabase recovery techniques
Database recovery techniques
 
DB2UDB_the_Basics Day 3
DB2UDB_the_Basics Day 3DB2UDB_the_Basics Day 3
DB2UDB_the_Basics Day 3
 
Memory management in oracle
Memory management in oracleMemory management in oracle
Memory management in oracle
 
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
DB2 LUW V11.1 CERTIFICATION TRAINING PART #1
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
 
Backup and recovery in oracle
Backup and recovery in oracleBackup and recovery in oracle
Backup and recovery in oracle
 
Recovery Techniques and Need of Recovery
Recovery Techniques and   Need of RecoveryRecovery Techniques and   Need of Recovery
Recovery Techniques and Need of Recovery
 
Memory management
Memory managementMemory management
Memory management
 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database Transactions
 
Introduction of Memory Management
Introduction of Memory Management Introduction of Memory Management
Introduction of Memory Management
 
Understanding memory management
Understanding memory managementUnderstanding memory management
Understanding memory management
 
Cache memory
Cache memoryCache memory
Cache memory
 
Process & Mutlithreading
Process & MutlithreadingProcess & Mutlithreading
Process & Mutlithreading
 
BACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMSBACKUP & RECOVERY IN DBMS
BACKUP & RECOVERY IN DBMS
 
SHADOW PAGING and BUFFER MANAGEMENT
SHADOW PAGING and BUFFER MANAGEMENTSHADOW PAGING and BUFFER MANAGEMENT
SHADOW PAGING and BUFFER MANAGEMENT
 
4 (1)
4 (1)4 (1)
4 (1)
 
DB2UDB_the_Basics
DB2UDB_the_BasicsDB2UDB_the_Basics
DB2UDB_the_Basics
 

En vedette

6.3 my sql queryoptimization_part2
6.3 my sql queryoptimization_part26.3 my sql queryoptimization_part2
6.3 my sql queryoptimization_part2Trần Thanh
 
6.1 query optimization overview
6.1 query optimization overview6.1 query optimization overview
6.1 query optimization overviewTrần Thanh
 
2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sql2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sqlTrần Thanh
 
Pdf bai 6 làm việc với truy vấn cơ bản-slide 06-quan tri csdl voi access-mast...
Pdf bai 6 làm việc với truy vấn cơ bản-slide 06-quan tri csdl voi access-mast...Pdf bai 6 làm việc với truy vấn cơ bản-slide 06-quan tri csdl voi access-mast...
Pdf bai 6 làm việc với truy vấn cơ bản-slide 06-quan tri csdl voi access-mast...MasterCode.vn
 
2.3 quan ly truy cap
2.3 quan ly truy cap2.3 quan ly truy cap
2.3 quan ly truy capTrần Thanh
 
Pdf bai 1 tổng quan về ms access-quan tri csdl voi access-mastercode.vn
Pdf bai 1 tổng quan về ms access-quan tri csdl voi access-mastercode.vnPdf bai 1 tổng quan về ms access-quan tri csdl voi access-mastercode.vn
Pdf bai 1 tổng quan về ms access-quan tri csdl voi access-mastercode.vnMasterCode.vn
 

En vedette (20)

6.3 my sql queryoptimization_part2
6.3 my sql queryoptimization_part26.3 my sql queryoptimization_part2
6.3 my sql queryoptimization_part2
 
8.replication
8.replication8.replication
8.replication
 
C3 2
C3 2C3 2
C3 2
 
5. indexing
5. indexing5. indexing
5. indexing
 
4.2 transaction 2
4.2 transaction 24.2 transaction 2
4.2 transaction 2
 
4.2 transaction
4.2 transaction4.2 transaction
4.2 transaction
 
6.1 query optimization overview
6.1 query optimization overview6.1 query optimization overview
6.1 query optimization overview
 
2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sql2.2 cac chuong trinh my sql
2.2 cac chuong trinh my sql
 
01 gioithieu
01 gioithieu01 gioithieu
01 gioithieu
 
2.1 view
2.1 view2.1 view
2.1 view
 
9. partitioning
9. partitioning9. partitioning
9. partitioning
 
07 trigger view
07 trigger view07 trigger view
07 trigger view
 
Pdf bai 6 làm việc với truy vấn cơ bản-slide 06-quan tri csdl voi access-mast...
Pdf bai 6 làm việc với truy vấn cơ bản-slide 06-quan tri csdl voi access-mast...Pdf bai 6 làm việc với truy vấn cơ bản-slide 06-quan tri csdl voi access-mast...
Pdf bai 6 làm việc với truy vấn cơ bản-slide 06-quan tri csdl voi access-mast...
 
C3 2 (tuan6,7)
C3 2 (tuan6,7)C3 2 (tuan6,7)
C3 2 (tuan6,7)
 
Chuan
ChuanChuan
Chuan
 
C4 1 tuan 14
C4 1 tuan 14C4 1 tuan 14
C4 1 tuan 14
 
C2 2
C2 2C2 2
C2 2
 
C3 1
C3 1C3 1
C3 1
 
2.3 quan ly truy cap
2.3 quan ly truy cap2.3 quan ly truy cap
2.3 quan ly truy cap
 
Pdf bai 1 tổng quan về ms access-quan tri csdl voi access-mastercode.vn
Pdf bai 1 tổng quan về ms access-quan tri csdl voi access-mastercode.vnPdf bai 1 tổng quan về ms access-quan tri csdl voi access-mastercode.vn
Pdf bai 1 tổng quan về ms access-quan tri csdl voi access-mastercode.vn
 

Similaire à 7. backup & restore data

MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAsMark Leith
 
iLAB OVERVIEWScenario and SummarySuccessful database recovery re.docx
iLAB OVERVIEWScenario and SummarySuccessful database recovery re.docxiLAB OVERVIEWScenario and SummarySuccessful database recovery re.docx
iLAB OVERVIEWScenario and SummarySuccessful database recovery re.docxrochellscroop
 
All types of backups and restore
All types of backups and restoreAll types of backups and restore
All types of backups and restoreVasudeva Rao
 
MySQL Backup and Security Best Practices
MySQL Backup and Security Best PracticesMySQL Backup and Security Best Practices
MySQL Backup and Security Best PracticesLenz Grimmer
 
17398351 sap-system-copy-homcopyv1
17398351 sap-system-copy-homcopyv117398351 sap-system-copy-homcopyv1
17398351 sap-system-copy-homcopyv1Mmusi Dithotse
 
Data Guard New Features
Data Guard New FeaturesData Guard New Features
Data Guard New Featuresxiangrong
 
MySQL Server Backup, Restoration, and Disaster Recovery Planning
MySQL Server Backup, Restoration, and Disaster Recovery PlanningMySQL Server Backup, Restoration, and Disaster Recovery Planning
MySQL Server Backup, Restoration, and Disaster Recovery PlanningLenz Grimmer
 
Get mysql clusterrunning-windows
Get mysql clusterrunning-windowsGet mysql clusterrunning-windows
Get mysql clusterrunning-windowsJoeSg
 
Multiple instance on windows
Multiple instance on windowsMultiple instance on windows
Multiple instance on windowsVasudeva Rao
 
Air Line Management System | DBMS project
Air Line Management System | DBMS projectAir Line Management System | DBMS project
Air Line Management System | DBMS projectAniketHandore
 

Similaire à 7. backup & restore data (20)

MySQL Backup & Recovery
MySQL Backup & RecoveryMySQL Backup & Recovery
MySQL Backup & Recovery
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
iLAB OVERVIEWScenario and SummarySuccessful database recovery re.docx
iLAB OVERVIEWScenario and SummarySuccessful database recovery re.docxiLAB OVERVIEWScenario and SummarySuccessful database recovery re.docx
iLAB OVERVIEWScenario and SummarySuccessful database recovery re.docx
 
All types of backups and restore
All types of backups and restoreAll types of backups and restore
All types of backups and restore
 
Mysql all
Mysql allMysql all
Mysql all
 
Mydumper
MydumperMydumper
Mydumper
 
Mysql all
Mysql allMysql all
Mysql all
 
C_mysql-1.ppt
C_mysql-1.pptC_mysql-1.ppt
C_mysql-1.ppt
 
Slides
SlidesSlides
Slides
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
 
Data administration
Data administrationData administration
Data administration
 
MySQL Backup and Security Best Practices
MySQL Backup and Security Best PracticesMySQL Backup and Security Best Practices
MySQL Backup and Security Best Practices
 
17398351 sap-system-copy-homcopyv1
17398351 sap-system-copy-homcopyv117398351 sap-system-copy-homcopyv1
17398351 sap-system-copy-homcopyv1
 
Data Guard New Features
Data Guard New FeaturesData Guard New Features
Data Guard New Features
 
MySQL Server Backup, Restoration, and Disaster Recovery Planning
MySQL Server Backup, Restoration, and Disaster Recovery PlanningMySQL Server Backup, Restoration, and Disaster Recovery Planning
MySQL Server Backup, Restoration, and Disaster Recovery Planning
 
Get mysql clusterrunning-windows
Get mysql clusterrunning-windowsGet mysql clusterrunning-windows
Get mysql clusterrunning-windows
 
Introduction Mysql
Introduction Mysql Introduction Mysql
Introduction Mysql
 
Mysql introduction
Mysql introduction Mysql introduction
Mysql introduction
 
Multiple instance on windows
Multiple instance on windowsMultiple instance on windows
Multiple instance on windows
 
Air Line Management System | DBMS project
Air Line Management System | DBMS projectAir Line Management System | DBMS project
Air Line Management System | DBMS project
 

Dernier

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

7. backup & restore data

  • 1. Hệ quản trị cơ sở dữ liệu Backup and Restore Data Dư Phương Hạnh Bộ môn Hệ thống thông tin Khoa CNTT, trường Đại học Công nghệ Đại học Quốc gia Hanoi hanhdp@vnu.edu.vn
  • 2. Outline  Using mysqldump utility to back up tables in a single or multiple databases.  Using backup files with mysql monitor to restore databases or tables.  Using binary logs to update restored databases.  Using various mysqldump Options. Read more at: http://mysql-tools.com/en/backup-restore-data-mysql.htm 2 Hệ quản trị CSDL @ BM HTTT
  • 3. Introduce  Despite the steps you take to secure and protect your databases, events such as power failures, natural disasters, and equipment failure can lead to the corruption and loss of data.  Ensure that MySQL databases are backed up regularly should be part of any maintenance routine.  These backup files will contain the database and table definitions necessary to re-create your database structure as well as the instructions necessary to repopulate your tables. 3 Hệ quản trị CSDL @ BM HTTT
  • 4. Introduce  Using these backup files, you can recover your data to the state it was in at the time you performed the last backup. Further, you can use the binary log files to recover your data to post-backup current state.  The mysqldump program is the primary method in MySQL for backing up tables and databases and it can back up individual databases, tables in those databases, or multiple databases. When you run mysqldump, the utility creates a text file that contains the SQL statements necessary to create your database and tables safely and add data to those tables. 4 Hệ quản trị CSDL @ BM HTTT
  • 5. Usage of mysqldump utility  It is possible to back up databases simply by copying the data directory to a backup location. This method has several limitations, though. – if data is being accessed and updated during file copy, you might be copying tables that are in an inconsistent state. – file-level copying may help MyISAM tables but InnoDB tables can be more complicated at file level. 5 Hệ quản trị CSDL @ BM HTTT
  • 6. Using mysqldump Syntax: mysqldump [options] dbname [tables] mysqldump [options] --databases [moreoptions] dbname1 [dbname2 ...] mysqldump [options] --all-databases [moreoptions] 6 Hệ quản trị CSDL @ BM HTTT
  • 7. Using mysqldump Options: --no-create-info: Creates no CREATE TABLE commands, but only the INSERT commands. --no-data : Creates no INSERT commands (but only CREATE TABLE commands in order to restore the database schema). 7 Hệ quản trị CSDL @ BM HTTT
  • 8. Set Variables  MySQL saves some system values in user-defined variables to restore the original system settings should they be changed by any of the statements while executing the backup file  thereby ensuring that your environment is left in the same state after the restore via execution of the statements in the backup file. 8 Hệ quản trị CSDL @ BM HTTT
  • 9. Set Variables /*!40101 SET @OLD_CHARACTER_SET_CLIENT=CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; SET statements begin with the /*! symbols and end with the */ symbols. The symbols ensure the statements are executed by MySQL but ignored if they are executed in another database management system The number followed those symbols represents a MySQL server version. 9 Hệ quản trị CSDL @ BM HTTT
  • 10. Flush Logs  Binary log files allow you to restore your database fully. The option --flush-logs flushes your log files and a new binary log file is created.  By flushing the logs, you get an exact starting point for using the binary logs when refreshing your restored database. It is recommended that you use the --flush- logs option whenever you back up your data. 10 Hệ quản trị CSDL @ BM HTTT
  • 11. Examples  Mysqldump –u root –pa sakila > D:ProgramsEasyPHPtmpsakila1.sql  mysqldump --flush-logs -u root -pa sakila > D:ProgramsEasyPHPtmpsakila1.sql  mysqldump –u root -pa -X sakila actor > D:ProgramsEasyPHPtmpactor1.xml  mysqldump --all-databases > D:ProgramsEasyPHPtmpall_db.sql; 11 Hệ quản trị CSDL @ BM HTTT
  • 12. Restore Data  If you have backed up your files regularly and enabled binary logging, restoring your database consists of two steps: – Use the mysql monitor to execute the backup script to reload a MySQL database. – Use the appropriate binary logs to update the database.  These two steps restore a database to the point of database errors, thus preventing any significant data loss in case of a faulure or a disaster. 12 Hệ quản trị CSDL @ BM HTTT
  • 13. Restore Data  If you are restoring data from a backup file that does not include a database definition, the database must exist before restoring. CREATE DATABASE sakila1; Use sakila1; Source D:ProgramsEasyPHPtmpsakila1.sql or Mysql –u root –pa test< 13 D:ProgramsEasyPHPtmpsakila1.sql Hệ quản trị CSDL @ BM HTTT
  • 14. Update the Restored db From Binary Log Files  Once database is reloaded, the data is only as current as your last backup, which is where binary logging comes in.  After you reload your database into your system, you will most likely want to get the database to its most current state since it was backed up. You will use binary logs which track all data modifications that occur in your databases. 14 Hệ quản trị CSDL @ BM HTTT
  • 15. Update the Restored db From Binary Log Files  MySQL provides two methods for applying updates from a binary log: – restoring data directly from the binary log file – exporting binary log data to a text file and then restoring it from that file.  You must have binary logging enabled on your system to be able to use it to update a restored database, covered in other lessons. 15 Hệ quản trị CSDL @ BM HTTT
  • 16. Restoring Data Directly From a Binary Log  Mysqld --log-bin  mysqlbinlog “D:ProgramsEasyPHPmysqldata HN-bin.000001”  mysqlbinlog "D:ProgramsEasyPHPmysqldataHN-bin.000001" > D:ProgramsEasyPHPmysqldatalog.txt  mysqlbinlog "D:ProgramsEasyPHPmysqldataHN-bin.000005" |mysql -u root –p --one-database sakila1 16 Hệ quản trị CSDL @ BM HTTT
  • 17. Restoring Binary Log Data From a Text File  You can sort through the text file to remove any statements that you don't want to execute.  The larger the log file, the more difficult this process can be, but there might be times when this is the only way you can ensure that your database is fully restored.  After you're satisfied that the text file contains only the correct statements, you can use the mysql client utility to execute the statements. 17 Hệ quản trị CSDL @ BM HTTT
  • 18. Restoring Binary Log Data From a Text File  Mysqlbinlog “D:ProgramsEasyPHPmysqldata HNbin.000001” > HN-bin000001.txt  After editing the text file as necessary, execute the statements in the text file.  Mysql -u root –p –one-database < HN-bin000001.txt 18 Hệ quản trị CSDL @ BM HTTT
  • 19. Exercise  Tạo CSDL test  Tạo bảng bảng table1(ID int, Text text);  Bật chế độ log-bin  Chèn dữ liệu vào bảng.  Backup test.  Xoá một bản ghi trong table1.  Khôi phục lại test từ file backup.  Sử dụng logs để khôi phục table1 về trạng thái gần 19 nhất (dùng 2 cách). Hệ quản trị CSDL @ BM HTTT