{"id":564,"date":"2019-01-29T18:38:10","date_gmt":"2019-01-29T15:38:10","guid":{"rendered":"https:\/\/artem.services\/?p=564"},"modified":"2019-02-21T15:32:08","modified_gmt":"2019-02-21T12:32:08","slug":"backup-sites-and-mysql-dbs-to-aws-s3","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=564","title":{"rendered":"BASH &#8212; \u0411\u0435\u043a\u0430\u043f \u0441\u0430\u0439\u0442\u043e\u0432 \u0438 \u0431\u0430\u0437 MySQL \u043d\u0430 AWS S3"},"content":{"rendered":"<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0432\u0441\u0435 \u043f\u0430\u043f\u043a\u0438, \u0438 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e \u0438\u0445 \u0430\u0440\u0445\u0438\u0432\u0438\u0440\u0443\u0435\u0442, \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u043d\u0430 <strong>S3 Bucket<\/strong> \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 <strong>MySQL<\/strong> \u0431\u0430\u0437, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435, \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e \u0438\u0445 \u0430\u0440\u0445\u0438\u0432\u0438\u0440\u0443\u0435\u0442, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 <strong>S3 Bucket<\/strong> \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n\r\nDATE=$(date +%d-%m-%Y)\r\nWEB_PATH=&quot;\/var\/www\/html\/&quot;\r\n\r\nSITE_LIST=&quot;$(ls $WEB_PATH)&quot;\r\nDB_LIST=&quot;$(mysql -u root -e &quot;SHOW DATABASES;&quot; | grep -Ev &quot;(Database|information_schema|performance_schema|mysql|sys)&quot;)&quot;\r\nS3_BUCKET=&quot;s3:\/\/artem-services&quot;\r\n\r\n################################ BACKUP SITES ################################\r\n\r\nfor SITE in $SITE_LIST\r\ndo\r\n\tif [ -f &quot;\/tmp\/$SITE.tar.gz&quot; ] # Check if there is an old archive left\r\n\tthen\r\n\t\trm \/tmp\/$SITE.tar.gz\r\n\tfi\r\n\r\n\ttar -zcvf \/tmp\/$SITE.tar.gz --directory=&quot;$WEB_PATH\/$SITE\/&quot; .\/\r\n\taws s3 cp \/tmp\/$SITE.tar.gz $S3_BUCKET\/$DATE\/SITE\/$SITE.tar.gz\r\n\trm \/tmp\/$SITE.tar.gz\r\ndone\r\n\r\n############################### BACKUP DATABASES ##############################\r\n\r\nfor DB in $DB_LIST\r\ndo\r\n\tif [ -f &quot;\/tmp\/$DB.gz&quot; ] # Check if there is an old archive left\r\n\tthen\r\n\t\trm \/tmp\/$DB.gz\r\n\tfi\r\n\r\n\tmysqldump -u root $DB | gzip -c &gt; \/tmp\/$DB.gz\r\n\taws s3 cp \/tmp\/$DB.gz $S3_BUCKET\/$DATE\/DATABASE\/$DB.gz\r\n\trm \/tmp\/$DB.gz\r\ndone\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043a\u0440\u0438\u043f\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0432\u0441\u0435 \u043f\u0430\u043f\u043a\u0438, \u0438 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e \u0438\u0445 \u0430\u0440\u0445\u0438\u0432\u0438\u0440\u0443\u0435\u0442, \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u043d\u0430 S3 Bucket \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 MySQL \u0431\u0430\u0437, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435, \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e \u0438\u0445 \u0430\u0440\u0445\u0438\u0432\u0438\u0440\u0443\u0435\u0442, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 S3 Bucket \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[157],"tags":[101,89,145,35,102],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/564"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=564"}],"version-history":[{"count":8,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/564\/revisions"}],"predecessor-version":[{"id":717,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/564\/revisions\/717"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}