summaryrefslogtreecommitdiff
path: root/lib/backup
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-09-15 10:24:30 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2015-09-15 20:14:21 +0200
commited18e04bb3d921d14f1bfb9adf7e0a4ad4dfc0b2 (patch)
tree118ae678c92aae63e89ebbb62db55c5e6bb02674 /lib/backup
parentb87ca7500f174cc9a4e90b262b02aa9bf695fbee (diff)
downloadgitlab-ce-ed18e04bb3d921d14f1bfb9adf7e0a4ad4dfc0b2.tar.gz
Cleanup CI backup => migrate with GitLab
Diffstat (limited to 'lib/backup')
-rw-r--r--lib/backup/builds.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/backup/builds.rb b/lib/backup/builds.rb
new file mode 100644
index 00000000000..4280438e86c
--- /dev/null
+++ b/lib/backup/builds.rb
@@ -0,0 +1,30 @@
+module Backup
+ class Builds
+ attr_reader :app_builds_dir, :backup_builds_dir, :backup_dir
+
+ def initialize
+ @app_builds_dir = File.realpath(Rails.root.join('ci/builds'))
+ @backup_dir = GitlabCi.config.backup.path
+ @backup_builds_dir = File.join(GitlabCi.config.backup.path, 'ci/builds')
+ end
+
+ # Copy builds from builds directory to backup/builds
+ def dump
+ FileUtils.mkdir_p(backup_builds_dir)
+ FileUtils.cp_r(app_builds_dir, backup_dir)
+ end
+
+ def restore
+ backup_existing_builds_dir
+
+ FileUtils.cp_r(backup_builds_dir, app_builds_dir)
+ end
+
+ def backup_existing_builds_dir
+ timestamped_builds_path = File.join(app_builds_dir, '..', "builds.#{Time.now.to_i}")
+ if File.exists?(app_builds_dir)
+ FileUtils.mv(app_builds_dir, File.expand_path(timestamped_builds_path))
+ end
+ end
+ end
+end