{"id":465,"date":"2018-02-02T05:08:50","date_gmt":"2018-02-02T05:08:50","guid":{"rendered":"http:\/\/www.asianux.org.vn\/?p=465"},"modified":"2018-02-02T05:08:50","modified_gmt":"2018-02-02T05:08:50","slug":"tu-dong-backup-du-lieu-ma-nguon-len-git","status":"publish","type":"post","link":"https:\/\/www.asianux.org.vn\/index.php\/2018\/02\/02\/tu-dong-backup-du-lieu-ma-nguon-len-git\/","title":{"rendered":"T\u1ef1 \u0111\u1ed9ng backup d\u1eef li\u1ec7u, m\u00e3 ngu\u1ed3n l\u00ean git"},"content":{"rendered":"<p>Ch\u00e0o c\u00e1c b\u1ea1n,<\/p>\n<p>C\u00f4ng vi\u1ec7c h\u00e0ng ng\u00e0y backup c\u01a1 s\u1edf d\u1eef li\u1ec7u, m\u00e3 ngu\u1ed3n kh\u00e1 m\u1ea5t c\u00f4ng. T\u00f4i th\u1eed vi\u1ebft m\u1ed9t \u0111o\u1ea1n sau \u0111\u1ec3 th\u1ef1c hi\u1ec7n backup d\u1eef li\u1ec7u m\u00e3 m\u00e3 ngu\u1ed3n c\u1ee7a t\u00f4i l\u00ean git. C\u00e1c b\u1ea1n tham kh\u1ea3o \u0111o\u1ea1n code sau:<\/p>\n<p>#!\/bin\/bash<\/p>\n<p># Database credentials<br \/>\nuser=&#8221;asianux_user&#8221;<br \/>\npassword=&#8221;asianux&#8221;<br \/>\nhost=&#8221;localhost&#8221;<br \/>\ndb_name=&#8221;db&#8221;<\/p>\n<p># Other options<br \/>\nbackup_path=&#8221;\/home\/asianux\/db&#8221;<br \/>\ndate=$(date +&#8221;%d-%b-%Y&#8221;)<\/p>\n<p># Set default file permissions<br \/>\numask 177<\/p>\n<p># Dump database into SQL file<br \/>\nmysqldump &#8211;user=$user &#8211;password=$password &#8211;host=$host $db_name &gt; $backup_path\/$db_name-$date.sql<\/p>\n<p># Delete files older than 30 days<br \/>\nfind $backup_path\/* -mtime +30 -exec rm {} \\;<\/p>\n<p># Push to git backup code and db<br \/>\nsleep 10<br \/>\ncd \/var\/asianux<br \/>\ngit add .<br \/>\ngit commit -m &#8220;Auto Commit Asianux&#8221;<br \/>\ngit push origin master<br \/>\necho &#8220;Backup code and db finish! Goodluck&#8221;<\/p>\n<p>Sau \u0111\u00f3 b\u1ea1n thi\u1ebft l\u1eadp ch\u1ea1y crontab \u0111\u1ec3 ch\u1ea1y t\u1ef1 \u0111\u1ed9ng.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ch\u00e0o c\u00e1c b\u1ea1n, C\u00f4ng vi\u1ec7c h\u00e0ng ng\u00e0y backup c\u01a1 s\u1edf d\u1eef li\u1ec7u, m\u00e3 ngu\u1ed3n kh\u00e1 m\u1ea5t c\u00f4ng. T\u00f4i th\u1eed vi\u1ebft m\u1ed9t \u0111o\u1ea1n sau \u0111\u1ec3 th\u1ef1c hi\u1ec7n backup d\u1eef li\u1ec7u m\u00e3 m\u00e3 ngu\u1ed3n c\u1ee7a t\u00f4i l\u00ean&hellip;<\/p>\n","protected":false},"author":1,"featured_media":466,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-465","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":1,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":467,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/465\/revisions\/467"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media\/466"}],"wp:attachment":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}