{"id":953,"date":"2021-03-22T15:32:37","date_gmt":"2021-03-22T14:32:37","guid":{"rendered":"https:\/\/devpath.pro\/?p=953"},"modified":"2021-03-22T15:32:37","modified_gmt":"2021-03-22T14:32:37","slug":"save-yourself-from-a-disaster-1-secure-the-database","status":"publish","type":"post","link":"https:\/\/fabiocicerchia.it\/web\/save-yourself-from-a-disaster-1-secure-the-database","title":{"rendered":"Save yourself from a disaster #1: Secure the Database"},"content":{"rendered":"
This is the first part of the series Save yourself from a disaster: Redundancy on a budget<\/a>.<\/p>\n How can we make sure our most important asset (which is the DB) is safely secured in case of a disaster?<\/p>\n We could do mainly 2 things (and you better do both of them):<\/p>\n Start doing the DB backups (with mysqldump<\/a> or xtrabackup<\/a>) and define a policy for RTO<\/a> and RPO<\/a>, so you’ll know what is the accepted loss (there’s always loss – even if very minimal). RTO defines how long can the infrastructure can be down, and RPO defines how much data can you afford to lose (ie. how old the latest backup is).<\/p>\n Rotation<\/strong><\/p>\n To rotate the DB backups we could simply use logrotate<\/a>. This will create the rotated DB backups on the same<\/span> server where logrotate is running (most likely the same DB instance). We have seen that this is very wrong, so you must always store the backups somewhere else (and also offline).<\/p>\n Remote Storage<\/strong> Local Storage<\/strong><\/p>\n Just do a rsync (better if scheduled) to download it locally to an external hard-drive:<\/p>\n There you go, you have now backups on-site (for faster restore), remote on another provider (for more reliability), offline (for more peace of mind).<\/p>\n Security<\/strong><\/p>\n Remember the good practices, and do not forget about GDPR<\/a>, the backups must be stored encrypted at-rest<\/a> (and use a key instead of a plain password<\/a>).<\/p>\n Once everything is backed up, you need to think about how to restore the dump properly, or at least switch the connection to the other node. I’ll cover this in the Disaster Recovery Plan post.<\/p>\n The next post will be about Secure the Storage, Stay Tuned.<\/p>\n Check out the whole version of this post in the ebook. This is the first part of the series Save yourself from a disaster: Redundancy on a budget. How can we make sure our most important asset (which is the DB) is safely secured in case of a disaster? We could do mainly 2 things (and you better do both of them): Backups Redundancy<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","footnotes":""},"categories":[14],"tags":[122,123,124,125],"aioseo_notices":[],"author_meta":{"display_name":"fabio","author_link":"https:\/\/fabiocicerchia.it\/author\/fabio"},"featured_img":null,"coauthors":[],"tax_additional":{"categories":{"linked":["Web<\/a>"],"unlinked":["Web<\/span>"]},"tags":{"linked":["disaster recovery<\/a>","ovh<\/a>","redundancy<\/a>","sbg2<\/a>"],"unlinked":["disaster recovery<\/span>","ovh<\/span>","redundancy<\/span>","sbg2<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 3 years ago","modified":"Updated 3 years ago"},"absolute_dates":{"created":"Posted on March 22, 2021","modified":"Updated on March 22, 2021"},"absolute_dates_time":{"created":"Posted on March 22, 2021 3:32 pm","modified":"Updated on March 22, 2021 3:32 pm"},"featured_img_caption":"","series_order":"","_links":{"self":[{"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/posts\/953"}],"collection":[{"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/comments?post=953"}],"version-history":[{"count":0,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/posts\/953\/revisions"}],"wp:attachment":[{"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/media?parent=953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/categories?post=953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/tags?post=953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\n
<\/h3>\n
\nThis guide won’t cover everything, it won’t be a comprehensive guide, and the steps that are shown need to be carefully reviewed and tested in your development\/pre-production environment. I don’t take any responsibility for any damage, interruption of service nor leak\/loss of data for the use of the instructions in the ebook (nor from any external website I’ve mentioned).<\/small><\/div>\nBackups<\/h2>\n
\nWe could simply start with a basic daily backup rotation (or any interval you have defined as RPO):<\/p>\n\/var\/backups\/daily\/alldb.sql.gz {\n notifempty\n daily\n rotate 7\n nocompress\n create 640 root adm\n dateext\n dateformat -%Y%m%d-%s\n\n postrotate\n mysqldump -u$USER -p$PASSWD --single-transaction --all-databases | gzip -9f > \/var\/backups\/daily\/alldb.sql.gz\n endscript\n}\n<\/pre>\n
\nWith a simple change, we can upload to an AWS S3 bucket<\/a> (with cold storage access set to rarely-used<\/a>):<\/p>\n lastaction\n BUCKET=\"...\"\n REGION=\"eu-west-1\"\n aws s3 sync \/var\/backups\/hourly \"s3:\/\/$BUCKET\/daily\/\" --region $REGION --exclude \"*\" --include \"*.gz-$FORMAT*\" --storage-class GLACIER\n endscript\n<\/pre>\n
rsync -e \"ssh -i $HOME\/.ssh\/id_rsa\" --progress -auv <USER>@<IP>:\/var\/backups .\/path\/to\/backups<\/pre>\n
Restore<\/h2>\n
\n
\n<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"