Sun Microsystems. MySQL Backup and Security Best practices on how to run MySQL on Linux in a secure way. Lenz Grimmer

Similar documents
1Z Oracle. MySQL 5 Database Administrator Certified Professional Part I

Bitnami MariaDB for Huawei Enterprise Cloud

Bitnami MySQL for Huawei Enterprise Cloud

MySQL Security, Privileges & User Management Kenny Gryp Percona Live Washington DC /

mysql Certified MySQL 5.0 DBA Part I

Oracle Exam 1z0-883 MySQL 5.6 Database Administrator Version: 8.0 [ Total Questions: 100 ]

mysql Sun Certified MySQL 5.0 Database(R) Administrator Part 1

Backing up or Exporting Databases Using mysqldump

Linux Administration

Backup & Restore. Maximiliano Bubenick Sr Remote DBA

Course 55187B Linux System Administration

1z0-888.exam.43q.

Exam LFCS/Course 55187B Linux System Administration

Percona Xtrabackup: Hot Backup Solution for MySQL

How to set up and verify automated MySQL backups in 15 minutes

At course completion. Overview. Audience profile. Course Outline. : 55187B: Linux System Administration. Course Outline :: 55187B::

"Charting the Course... MOC B: Linux System Administration. Course Summary

Creating a Best-in-Class Backup and Recovery System for Your MySQL Environment. Akshay Suryawanshi DBA Team Manager,

IT Certification Exams Provider! Weofferfreeupdateserviceforoneyear! h ps://

FUJITSU Cloud Service S5 Installation and Configuration of MySQL on a CentOS VM

Operational DBA In a Nutshell - HandsOn Reference Guide

MySQL Backup solutions. Liz van Dijk Zarafa Summer Camp - June 2012

MySQL Backup Best Practices and Case Study:.IE Continuous Restore Process

Support for replication is built into MySQL. There are no special add-ins or applications to install.

Quest NetVault Backup Plug-in for MySQL

MMM. MySQL Master-Master Replication Manager. Pascal Hofmann

RedHat Certified Engineer

How to get MySQL to fail

Oracle 1Z MySQL 5.6 Database Administrator. Download Full Version :

Dell Protected Workspace Management

Backup Strategies with MySQL Enterprise Backup

Backing Up And Restoring Your Nagios XI System

Check Table Oracle Database Status Windows Script

MySQL and Virtualization Guide

MySQL Enterprise Backup User's Guide (Version 3.6.1)

2) One of the most common question clients asks is HOW the Replication works?

Zmanda Recovery Manager Guide to MySQL Backup & Recovery

MySQL 5.x on QNX Neutrino OS Step-by-step installation manual

Linux Network Administration. MySQL COMP1071 Summer 2017

Mysql Manual Error Log Location Windows Server

How To Start Mysql Use Linux Command Line Client In Xampp

How to recover a lost administrator password?

ApsaraDB for RDS. Quick Start (MySQL)

Performing Administrative Tasks

Introduction to MySQL Cluster: Architecture and Use

Taking hot backups with XtraBackup. Principal Software Engineer April 2012

Zmanda Cloud Backup FAQ

MySQL Enterprise Backup User's Guide (Version 3.7.1)

Testing and Verifying your MySQL Backup Strategy

Database Backup and Recovery Best Practices. Manjot Singh, Data & Infrastrustructure Architect

HP-UX System Administration Course Overview. Skills Gained. Who will the Course Benefit?

Acronis Backup plugin for WHM and cpanel 1.0

Bitnami Tiny Tiny RSS for Huawei Enterprise Cloud

Veritas NetBackup for MySQL Administrator's Guide

Veritas NetBackup for MySQL Administrator's Guide

Abstract. This is the MySQL OS X extract from the MySQL 5.7 Reference Manual. For legal information, see the Legal Notices.

Unit 2: Manage Files Graphically with Nautilus Objective: Manage files graphically and access remote systems with Nautilus

Backup Manager. Jimmy / Linuxtage Chemnitz. Jimmy Backup Manager CLT06 1 / 17

Bitnami Dolibarr for Huawei Enterprise Cloud

Bitnami Re:dash for Huawei Enterprise Cloud

Bitnami Piwik for Huawei Enterprise Cloud

Operating Systems Linux 1-2 Measurements Background material

AudBase Security Document Page 0. Maintaining Data Security and Integrity

Model Question Paper. Credits: 4 Marks: 140

COS 318: Operating Systems. File Systems. Topics. Evolved Data Center Storage Hierarchy. Traditional Data Center Storage Hierarchy

Storage and File System

Bitnami ez Publish for Huawei Enterprise Cloud

Acronis Backup plugin for WHM & cpanel 1.0

How To Start Mysql Use Linux Command Line Client In Ubuntu

Getting Started with MySQL

MySQL Security. Domas Mituzas, Sun Microsystems

Bitnami Pimcore for Huawei Enterprise Cloud

CO MySQL for Database Administrators

Dell NetVault Backup Plug-in for MySQL 4.4. User s Guide

Bitnami Coppermine for Huawei Enterprise Cloud

Oracle VM Template for MySQL Enterprise Edition =========================================================================== ===

Mysqldump Schema Only No Lock

MySQL Architecture and Components Guide

Architecture. Steven M. Bellovin October 31,

File Protection using rsync. User guide

Protecting MySQL network traffic. Daniël van Eeden 25 April 2017

Bitnami TestLink for Huawei Enterprise Cloud

Bitnami OroCRM for Huawei Enterprise Cloud

File Protection Whitepaper

IT Service Delivery and Support Week Three. IT Auditing and Cyber Security Fall 2016 Instructor: Liang Yao

How To Start Mysql Use Linux Command Line Windows 7

Note The Garoon 3 system is not available while backing up. You must use the same version of Garoon 3 to perform data backup and restoration.

Why we re excited about MySQL 8

Operating and Maintaining Cisco SPS

MySQL Port Reference

Percona XtraBackup: install, usage, tricks. Do I/you need a backup?

MySQL Point-in-Time Recovery like a Rockstar

Data Integrity: Backups and RAID

MySQL Enterprise Backup User's Guide (Version 3.8.2)

Setting Up the Dell DR Series System as an NFS Target on Amanda Enterprise 3.3.5

Offloading MySQL to Remote Server

1Z MySQL Cloud Service 2018 Implementation Essentials Exam Summary Syllabus Questions

Setting Up the DR Series System as an NFS Target on Amanda Enterprise 3.3.5

Bitnami Mantis for Huawei Enterprise Cloud

Cloud Compute. Backup Portal User Guide

Transcription:

MySQL Backup and Security Best practices on how to run MySQL on Linux in a secure way Lenz Grimmer <lenz.grimmer@sun.com> DrupalCon 2008 Szeged, Hungary 28. August 2008 Sun Microsystems 1

Introduction Learning best practises about configuring and running MySQL in a secure way Security mechanisms built into MySQL and how to improve them by using OS features Discussion of MySQL backup possibilities/tools and strategies > Physical vs. logical backup > OSS tools suitable for backup purposes > Commercial backup solutions 2

Improving MySQL security Essential part of the post-installation process: Security Default installation pretty secure already Some additional steps have to be performed Also utilize additional security features provided by the OS (where applicable) 3

MySQL Server post-installation Set a password for the root account $ mysql u root mysql mysql> SET PASSWORD FOR root@localhost=password('new_password'); Remove the anonymous account (or assign a password to it) Remove the test database (you usually don't need it) mysql_secure_installation script does all of the above (Unix only) 4

Access Control Check Connect > Server checks in the user table for a matching entry for the username, host and password Query > Server checks the user, db, tables_priv and column_privs tables 5

Query Access Control Do you have sufficient privileges to execute the query? Query user true false true db false tables_priv Query executed true false columns_priv true false Permission denied 6

MySQL Server security hints bind-address option in my.cfg binds the TCP port to a specific interface (e.g. 127.0.0.1) skip-networking option only allows connections via the local socket file Allow access from selected hosts only Restrict access to the mysql.user table to the root user Learn how to use the SHOW GRANTS, SET PASSWORD and GRANT/REVOKE statements Use phpmyadmin or MySQL Administrator for user administration Do not edit mysql.user directly! 7

MySQL Server security hints Restrict PROCESS/SUPER/FILE privileges to a minimum Do not store plain-text passwords in the database. Use MD5(), SHA1() or some other one-way hashing function instead. Disable LOAD DATA LOCAL by setting localinfile=0 in my.cnf Always run run mysqld using a non-privileged user account 8

MySQL Server security hints For the paranoid: > replace the root account with a different(harder to guess) one to avoid brute-force dictionary attacks > remove/clean the client's history file (~/.mysql_history), if you edited or added user accounts/passwords 9

Views and Stored Procedures Views to restrict access to certain columns of tables Stored Procedures shield tables from being accessed/modified by the user/application directly Available since MySQL 5.0.x 10

Improving access restrictions Lock down permissions on the data directory with chown and chmod > users can t corrupt table data > users can't access data they aren t supposed to see Log files must also be kept secure: > users might again see data they aren t supposed to see > queries such as GRANT are stored in the logfiles, anyone with log file access could then obtain user passwords Generally don't allow shell logins to the DB server for normal users 11

Reducing security risks with Linux Use iptables to firewall the server Run MySQL in a chroot() jail Enable SELinux or Novell AppArmor Run the MySQL server in a virtual machine > > > > Xen / Sun xvm Solaris Zones/Container UML (User Mode Linux) VMware / Parallels / VirtualBox 12

Securing data and communication Encrypt network traffic > > > > OpenSSL SSH tunnel OpenVPN Cipe Encrypt the Data Directory > cryptoloop devices > dm_crypt kernel module 13

Backing up MySQL data When do you need backups? What needs to be backed up? When should backups be performed? Where will the backups be stored? How can backups be performed? 14

When Do You Need Backups? Hardware failure > A system crash may cause some of the data in the databases to be lost > A hard disk failure will most certainly lead to lost data User/Application failure > Accidental DROP TABLE or malformed DELETE FROM statements > Editing the table files with text editors, usually leading to corrupt tables 15

What needs to be backed up? Database content > for full backups > logical or physical backup Log files > for incremental backups > point-in-time recovery 16

When should backups be performed? On a regular basis Not during high usage peaks (off hours) Static data can be backed up less frequently 17

Where to store backups? On the database server > At least on a separate file system/volume or hard disk drive Copied to another server > On or off site Backed up to tape/disk > Stored on or off site Choose multiple locations 18

The Data Directory Databases and most log and status files are stored in the data directory by default Default directory compiled into the server > /usr/local/mysql/data/ (tarball installation) > /var/lib/mysql (RPM packages) Data directory location can be specified during server startup with datadir=/path/to/datadir/ Find out the location by asking the server mysql> SHOW VARIABLES like 'data%'; 19

The Binary Log Contains all SQL commands that change data Also contains additional information about each query (e.g. query execution time) Binary log is stored in an efficient binary format Use mysqlbinlog to decipher the log contents Log turned on with log bin[=file_name] Update logs are created in sequence e.g. file_name bin.001, file_name bin.002, etc. Binary log is transaction-compatible mysqld creates binary log index file which contains names of the binary log files used 20

Managing The Binary Log Purpose of the Binary Log: Enable replication Ease crash recovery SHOW MASTER LOGS shows all binary log files residing on the server FLUSH LOGS or restarting the server creates a new file RESET MASTER deletes all binary log files PURGE MASTER deletes all binary log files up to a certain point Don't delete logs that slaves still need 21

The Error Log When started with mysqld_safe, all error messages are directed to the error log The log contains info on when mysqld was started and stopped as well as errors found when running $ cat /var/log/mysql.err 000929 15:29:45 mysqld started /usr/sbin/mysqld: ready for connections 000929 15:31:15 Aborted connection 1 to db: 'unconnected' user: 'root' host: `localhost' (Got an error writing communication packets) 000929 15:31:15 /usr/local/mysql/bin/mysqld: Normal shutdown 000929 15:31:15 /usr/local/mysql/bin/mysqld: Shutdown Complete 000929 15:31:54 mysqld started /usr/sbin/mysqld: ready for connections 22

mysqldump mysqldump dumps table structure and data into SQL statements $ mysqldump mydb > mydb.20050925.sql You can dump individual tables or whole databases The default output from mysqldump consists of SQL statements: CREATE TABLE statements for table structure INSERT statements for the data mysqldump can also be used directly as input into another mysqld server (without creating any files) $ mysqldump opt world mysql hwork.mysql.com world 23

Recovering With Backups DB Recovery = Last full backup & binlog To restore tables to the state before a crash requires both the backup files and the binary log > Restore the tables to the state they were at the time of the backup from the backup files > Extract the queries issued between the backup and now from synchronised binary logs If you are recovering data lost due to unwise queries, remember not to issue them again 24

Example SQL level restore Restore the last full backup mysql < backup.sql apply all incremental changes done after the last full backup mysqlbinlog hostname-bin.000001 mysql 25

MySQL table files backup Also called physical backup MyISAM Database files can simply be copied after issuing FLUSH TABLES WITH READ LOCK; The mysqlhotcopy Perl script automates this process Locking all tables for consistency can be expensive, if the file backup operation takes a long time 26

mysqlhotcopy mysqlhotcopy is a Perl script with which you can easily backup databases It can only be run on the same machine as where the databases are It does the following LOCK TABLES FLUSH TABLES Copies the table files to the desired location with cp or scp UNLOCK TABLES The user has to have write access to the target directory 27

Backing Up InnoDB Databases Use mysqldump --single transaction to make an on line backup To take a binary backup, do the following: 1. Shutdown the MySQL server 2. Copy your data files, InnoDB log files,.frm files and my.cnf file(s) to a safe location 3. Restart the server It is a good idea to backup with mysqldump also, since an error might occur in a binary file without you noticing it 28

OSS backup tools The usual suspects: cp, tar, cpio, gzip, zip called in a shell script via a cron job rsync or unison for bandwidth-friendly, remote backups Complete network-based backup solutions like afbackup, Amanda or Bacula provide more sophisticated features (e.g. catalogs) 29

Linux backup support LVM snapshots DRBD ( RAID1 over the network ) Distributed file systems > > > > OpenAFS GFS Lustre Novell ifolder 30

Backup using LVM snapshots Linux LVM snapshots provide a very convenient and fast backup solution for backing up entire databases without disruption Snapshot volume size does not need to be very large (10-15% are sufficient in a typical scenario) Backup of files from a snapshot volume can be performed with any tool I/O performance may be degraded due to the additional LVM logging 31

Linux LVM snapshot creation Basic principle: mysql> FLUSH TABLES WITH READ LOCK $ lvcreate -s -size=<size> --name=backup <LV> mysql> UNLOCK TABLES $ mount /dev/<vg>/backup /mnt $ tar czvf backup.tar.gz /mnt/* $ umount /mnt $ lvremove /dev/<vg>/backup 32

The mylvmbackup script A Perl script for quickly creating MySQL backups using LVM snapshots Snapshots are mounted to a temporary directory and all data is backed up using tar or rsync Timestamped archive names allow running mylvmbackup many times without risking to overwrite old archives. Requires Perl, DBI and DBD::mysql Available from http://www.lenzg.org/mylvmbackup/ 33

MySQL replication Backing up a replication slave is less time-critical (Master is not blocked for updates) A slave can use different storage engines One Master can replicate to many slaves Keep the limitations of MySQL replication in mind Make sure to back up the master.info and relaylog.info files as well as any SQL_LOAD-* files (if LOAD DATA INFILE is replicated) 34

Commercial backup solutions Acronis True Image ARCServe Arkeia InnoDB HotBackup SEP sesam Veritas vxfs snapshots Zmanda Recovery Manager (ZRM) 35

Backup Method Comparison Output from mysqldump is portable to any other DBMS (without the opt option) whereas copied files only work with MySQL Full backups are expensive Restoring from logs can be tricky The file copying methods are much faster than mysqldump So it comes down to your preferences: Which tool do you prefer to use Speed vs. portability 36

Backup Principles Perform backups regularly Turn on the binary update log > Update logs are needed to restore the database without losing any data Synchronise update logs with the backup files > Use FLUSH LOGS Name your backups consistently and understandably > Include the date in the file name mydb.20050925.sql Store your backups on a different file system than where your databases are 37

General backup notes Putting the binary logs on a different file system (or even a different drive) than the data directory is recommended (increases performance and avoids data loss) Verify the backup is consistent and complete! Define backup schedules and policies as well as recovery procedures Test that these actually work! 38

The MySQL Online Backup API An API to perform a streaming MySQL online backup, independent of the Storage Engine Transactional tables will contain data only from committed transactions Non-transactional tables will contain data only from completed statements Referential integrity will be maintained between all tables backed up with a specific backup command Now available on MySQL Forge: http://forge.mysql.com/wiki/onlinebackup 39

Thank you! Questions, Comments? Lenz Grimmer <lenz.grimmer@sun.com> 40