{"id":585,"date":"2023-02-14T09:15:46","date_gmt":"2023-02-14T09:15:46","guid":{"rendered":"https:\/\/www.asianux.org.vn\/?p=585"},"modified":"2023-02-14T09:15:47","modified_gmt":"2023-02-14T09:15:47","slug":"backup-gitlab","status":"publish","type":"post","link":"https:\/\/www.asianux.org.vn\/index.php\/2023\/02\/14\/backup-gitlab\/","title":{"rendered":"Backup GitLab"},"content":{"rendered":"\n<p>\u0110\u1ec3 th\u1ef1c hi\u1ec7n vi\u1ec7c backup GitLab v\u00e0 l\u01b0u b\u1ea3n sao l\u01b0u c\u00f3 t\u00ean ch\u1ee9a ng\u00e0y th\u00e1ng n\u0103m, gi\u1eef l\u1ea1i 3 b\u1ea3n sao l\u01b0u m\u1edbi nh\u1ea5t v\u00e0 sao ch\u00e9p b\u1ea3n sao l\u01b0u m\u1edbi nh\u1ea5t sang m\u00e1y ch\u1ee7 kh\u00e1c th\u00f4ng qua ssh key, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng script bash sau:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\r\n\r\n# GitLab backup directory\r\nbackup_dir=\"\/var\/opt\/gitlab\/backups\/\"\r\n\r\n# Create the backup directory if it doesn't exist\r\nif &#91; ! -d \"$backup_dir\" ]; then\r\n    mkdir -p \"$backup_dir\"\r\nfi\r\n\r\n# Backup GitLab and name the backup file with the current date and time\r\nbackup_file=\"$backup_dir$(date +%Y-%m-%d_%H-%M-%S)_gitlab_backup.tar\"\r\n\r\ngitlab-rake gitlab:backup:create BACKUP=$backup_file\r\n\r\n# Keep only the 3 most recent backups and delete the rest\r\ncd \"$backup_dir\"\r\nls -t | grep -v -E \"$(ls -t | head -n 3 | sed 's\/$\/|\/' | tr -d '\\n')\" | xargs rm -f\r\n\r\n# Copy the newest backup file to another server via ssh key\r\nremote_server=\"user@remote-server\"\r\nremote_backup_dir=\"\/var\/opt\/gitlab\/backups\/\"\r\n\r\nnewest_backup_file=$(ls -t | head -n 1)\r\n\r\nscp -i \/path\/to\/ssh\/key \"$backup_dir$newest_backup_file\" \"$remote_server:$remote_backup_dir\"\r\n<\/code><\/pre>\n\n\n\n<p>Gi\u1ea3i th\u00edch c\u00e1c b\u01b0\u1edbc trong script:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Thi\u1ebft l\u1eadp \u0111\u01b0\u1eddng d\u1eabn cho th\u01b0 m\u1ee5c sao l\u01b0u GitLab.<\/li>\n\n\n\n<li>Ki\u1ec3m tra xem th\u01b0 m\u1ee5c sao l\u01b0u \u0111\u00e3 t\u1ed3n t\u1ea1i ch\u01b0a, n\u1ebfu kh\u00f4ng th\u00ec t\u1ea1o m\u1edbi th\u01b0 m\u1ee5c.<\/li>\n\n\n\n<li>Th\u1ef1c hi\u1ec7n sao l\u01b0u GitLab v\u00e0 \u0111\u1eb7t t\u00ean t\u1ec7p sao l\u01b0u theo ng\u00e0y gi\u1edd hi\u1ec7n t\u1ea1i.<\/li>\n\n\n\n<li>Gi\u1eef l\u1ea1i ch\u1ec9 3 b\u1ea3n sao l\u01b0u m\u1edbi nh\u1ea5t v\u00e0 x\u00f3a c\u00e1c b\u1ea3n sao l\u01b0u c\u0169 h\u01a1n.<\/li>\n\n\n\n<li>Sao ch\u00e9p t\u1ec7p sao l\u01b0u m\u1edbi nh\u1ea5t sang m\u00e1y ch\u1ee7 kh\u00e1c qua ssh key, s\u1eed d\u1ee5ng l\u1ec7nh scp.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u0110\u1ec3 th\u1ef1c hi\u1ec7n vi\u1ec7c backup GitLab v\u00e0 l\u01b0u b\u1ea3n sao l\u01b0u c\u00f3 t\u00ean ch\u1ee9a ng\u00e0y th\u00e1ng n\u0103m, gi\u1eef l\u1ea1i 3 b\u1ea3n sao l\u01b0u m\u1edbi nh\u1ea5t v\u00e0 sao ch\u00e9p b\u1ea3n sao l\u01b0u m\u1edbi nh\u1ea5t sang m\u00e1y&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-585","post","type-post","status-publish","format-standard","hentry","category-programing"],"_links":{"self":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/585","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=585"}],"version-history":[{"count":1,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/585\/revisions"}],"predecessor-version":[{"id":587,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/585\/revisions\/587"}],"wp:attachment":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media?parent=585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/categories?post=585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/tags?post=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}