Commit Graph

64 Commits

Author SHA1 Message Date
Ted Strzalkowski 7430e7b5fc Workaround the warnings emitted by MySQL 5.6 regarding password on the
command line.
2015-08-12 07:51:24 -07:00
Dmitriy Zaporozhets b118f648cb Merge branch 'master' of github.com:gitlabhq/gitlabhq 2015-08-03 11:04:04 +02:00
Jacob Vosmaer baa157926d Stricter mkdir's in 'rake gitlab:backup:create' 2015-07-30 10:17:34 +02:00
Jacob Vosmaer c5aae30773 Set internal backup directory modes on create
This sidesteps problems with running 'chmod' on some CIFS mounts.
2015-07-29 11:18:55 +02:00
Jacob Vosmaer 0be6debb0b Merge branch 'master' of dev.gitlab.org:gitlab/gitlabhq into backup-archive-permissions 2015-07-27 11:22:35 +02:00
Jacob Vosmaer 346b074979 Don't stop if database.sql.gz already exists
The existing behavior of the backups is to overwrite whatever data
was still there in the scratch directories. This broke when we added
a 'gzip' step because 'gzip database.sql' will fail if 'database.sql.gz'
already exists. Doing 'rm -f database.sql.gz' before the 'gzip'
avoids this failure.
2015-07-21 10:37:27 +02:00
Dmitriy Zaporozhets b9452d7bcd Merge branch 'improve-postgres-restore-cleaning' into 'master'
Use native Postgres database cleaning during backup restore

We were using hacks to drop tables etc during a Postgres backup
restore. With this change, we let pg_dump insert the DROP TABLE
statements it needs at the start of the SQL dump.

See merge request !1891
2015-07-07 23:02:48 +00:00
Jacob Vosmaer 90ab5a59bb Use native Postgres database cleaning during backup restore
We were using hacks to drop tables etc during a Postgres backup
restore. With this change, we let pg_dump insert the DROP TABLE
statements it needs at the start of the SQL dump.
2015-07-07 15:34:06 +02:00
Jacob Vosmaer bb50b7fcd0 Allow custom backup archive permissions
This change helps system administrators who want to replicate
GitLab backup files without needing root permissions.
2015-07-06 18:43:17 +02:00
Kamil Trzcinski 69c659ebd3 Compress database backup 2015-07-06 17:14:17 +02:00
Dmitriy Zaporozhets 0214a21db5 Merge branch 'restore_uploads_fix' into 'master'
Avoid "cannot copy directory ... to itself" error on restore (on Docker?)

rake gitlab:backup:restore fails for me in my Docker-hosted Gitlab-CE instance; during the restore, any existing "uploads" directory is backed up by [this code](https://gitlab.com/gitlab-org/gitlab-ce/blob/833bc30/lib/backup/uploads.rb#L23) --

```ruby
    def backup_existing_uploads_dir
      timestamped_uploads_path = File.join(app_uploads_dir, '..', "uploads.#{Time.now.to_i}")
      if File.exists?(app_uploads_dir)
        FileUtils.mv(app_uploads_dir, timestamped_uploads_path)
      end
    end
```

When this executes for me, the ```FileUtils.mv``` parameters are "/home/git/gitlab/public/uploads" and "/home/git/gitlab/public/uploads/../uploads.1407019546"; an exception is raised, producing this double stacktrace:

```
ArgumentError: cannot copy directory /home/git/gitlab/public/uploads to itself /home/git/gitlab/public/uploads/../uploads.1407019546
/home/git/gitlab/lib/backup/uploads.rb:26:in `backup_existing_uploads_dir'
/home/git/gitlab/lib/backup/uploads.rb:18:in `restore'
/home/git/gitlab/lib/tasks/gitlab/backup.rake:73:in `block (4 levels) in <top (required)>'
/home/git/gitlab/lib/tasks/gitlab/backup.rake:30:in `block (3 levels) in <top (required)>'
Errno::EXDEV: Invalid cross-device link @ sys_fail2 - (/home/git/gitlab/public/uploads, /home/git/gitlab/public/uploads/../uploads.1407019546)
/home/git/gitlab/lib/backup/uploads.rb:26:in `backup_existing_uploads_dir'
/home/git/gitlab/lib/backup/uploads.rb:18:in `restore'
/home/git/gitlab/lib/tasks/gitlab/backup.rake:73:in `block (4 levels) in <top (required)>'
/home/git/gitlab/lib/tasks/gitlab/backup.rake:30:in `block (3 levels) in <top (required)>'
Tasks: TOP => gitlab:backup:uploads:restore
(See full trace by running task with --trace)
```

I'm guessing from the first message that ```mv``` walks the destination path to ensure that we're not moving the source into itself -- it doesn't get as far as interpreting the '..', but throws when it sees that the destination appears to start with the source path.

The second stacktrace I have no clue about - maybe it's AUFS- or Docker-related?

I attempted to reproduce this separately with the omnibus distribution in a fresh Ubuntu 14.04 install without Docker involved, and was unable to - backup and restore worked fine. I then tested my theory by FileUtils.expand_path-ing the destination in my own Docker setup code, and that made the problem go away, so that's what this merge request does.

(I'm using backups created and restored on gitlab-ce 7-1-stable, at facfec4b2; this is on Ubuntu 14.04 with Docker 1.1.1)

I know I'd look askance at a PR without tests for an unreproducable problem, but even if this is rejected, I'm submitting it anyway because maybe someone else will Google it and find it useful. I'm happy to do more work to improve this if you have suggestions.

See merge request !165
2015-06-22 09:52:42 +00:00
Jeroen Nijhof a7047569db use gitlab not gitlabci 2015-06-09 18:30:38 +02:00
Jeroen Nijhof bf7315cb13 update fog to 1.25.0 and add multipart upload support 2015-06-09 17:56:37 +02:00
Valery Sizov 67c83489ca ability to skip some items in backup 2015-04-02 15:37:50 +03:00
Vinnie Okada 0f78d92e4c Don't use chmod_R for backup tars
When creating backup tar files, only change permissions on the `db`,
`uploads`, and `repositories` directories, not their contents.
2015-03-28 08:38:48 -06:00
Vinnie Okada 083027fc84 Change directory when removing old backups 2015-03-24 20:47:11 -06:00
Dmitriy Zaporozhets aadd38dbb9 Merge branch 'backup-permissions' into 'master'
Change permissions on backup files - #2

Use more restrictive permissions for backup tar files and for the db, uploads, and repositories directories inside the tar files.  See #1894.  Now the backup task recursively `chmod`s the `db/`, `uploads/`, and `repositories/` folders with 0700 permissions, and the tar file is created as 0600.

This is a followup to !1703, which was reverted because it broke Rspec tests.  The test failures were due to the rake task changing directories and not changing back, which I fixed with this commit.

cc @sytse

See merge request !1716
2015-03-21 23:50:20 +00:00
Vinnie Okada 06aafb7364 Call chdir() with a block 2015-03-19 20:30:19 -06:00
Valery Sizov d411a9e4d8 backup repo with tar instead of git bundle 2015-03-19 14:36:02 +02:00
Vinnie Okada 61c06c5e1a Change permissions on backup files
Use more restrictive permissions for backup tar files and for the db,
uploads, and repositories directories inside the tar files.
2015-03-17 19:04:21 -06:00
Dmitriy Zaporozhets 3a324d9c6d Revert "Merge branch 'backup-permissions' into 'master'"
This reverts commit c42262b43b, reversing
changes made to c6586b1283.
2015-03-16 23:51:46 -07:00
Vinnie Okada 8587a29370 Change permissions on backup files
Use more restrictive permissions for backup tar files and for the db,
uploads, and repositories directories inside the tar files.
2015-03-15 13:14:30 -06:00
Dmitriy Zaporozhets 8184a65644 Revert "Fix broken access control and refactor avatar upload"
This reverts commit 7d5f86f6cb.
2015-02-19 08:57:35 -08:00
Hannes Rosenögger 7d5f86f6cb Fix broken access control and refactor avatar upload
This commit moves the note folder from
/public/uploads/note
to
/uploads/note
and changes the uploader accordingly.
Now it's no longer possible to avoid the access control by modifing the url.
The Avatar upload has been refactored to use an own uploader as well
to cleanly seperate the two upload types.
2015-02-16 20:10:15 +01:00
Achilleas Pipinellis 191aa9712e Properly fix wiki restore.
ProjectWiki.new() creates a new wiki git repository, so any tries
to bare clone a bundle fail. With this patch we remove the newly
created wiki.git before restoring from the backup bundle.
2014-11-30 18:24:05 +02:00
Achilleas Pipinellis 880478b21e Proper wiki restore. Fixes #845 2014-11-29 22:01:52 +02:00
Jacob Vosmaer 7c54c63ac1 Add CRON=1 backup setting for quiet backups 2014-11-20 15:46:04 +01:00
Dimitry Andric 4a5044e302 Correctly restore empty repositories.
If a project is being restored, but there is no bundle file, the project was
empty when it was backed up.  In this case, just use git init --base to create a
new bare repository.
2014-11-13 13:09:47 +01:00
Valery Sizov 1a7e347635 Merge remote-tracking branch 'origin/master' into backup_restore_drop_sequences
Conflicts:
	CHANGELOG
2014-11-12 13:14:13 +02:00
Ciro Santilli e4a38e4471 Factor using Repository#path_to_repo 2014-11-05 17:51:49 +01:00
Jacob Vosmaer e00e67db42 Drop all Postgres sequences during backup restore 2014-10-28 18:52:21 +01:00
Jacob Vosmaer 8ad1330b6a Ask the wiki repo, not Gollum, if it's empty
We need to skip empty repositories when creating a backup. Before this
change, we were asking gollum-lib if the wiki contains any _pages_. Now
we ask gitlab_git if the repository contains _files_. This should
resolve gollum_lib Grit timeouts in the backup script.
2014-10-20 10:52:29 +02:00
Jacob Vosmaer 02bf992f37 Fail harder in the backup script
This change also shows the output of failed Git commands during the
backup.
2014-10-01 15:43:27 +02:00
Jacob Vosmaer e1f6fa6f18 Add backup upload support to the rake task 2014-09-29 15:03:08 +02:00
Jacob Vosmaer 042465c448 Use create-hooks instead of rewrite-hooks.sh
The rewrite-hooks.sh script is a deprecated wrapper for gitlab-shell's
create-hooks script.
2014-09-08 10:16:15 +02:00
Bryan Stearns fc9832b1e6 Avoid "cannot copy directory to itself" restore error 2014-08-03 13:42:11 -07:00
Jacob Vosmaer 0f29ccffd2 Backup wiki repo even if the main repo is empty
This fixes a bug where wiki repositories for projects with an empty main
repository would not get backed up.
2014-05-08 22:50:48 +02:00
Jacob Vosmaer da347d1bb4 Apply the locale encoding to `tar --version`
Fixes a bug with non-UTF8 locales introduced by
2b816075dc.
2014-05-08 18:23:44 +02:00
Dmitriy Zaporozhets 1bd28994cc
Use ProjectWiki instead of GollumWiki in code
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-04-09 14:35:58 +03:00
Jacob Vosmaer 77b57c114b Drop all tables before restoring a PostgreSQL DB
Invoking 'db:schema:load' turned out to be a bad idea: when downgrading
an existing GitLab installation, the schema of the newer version would
be preserved when trying to import the old version.
2014-03-28 13:44:46 +01:00
Jacob Vosmaer 2b816075dc Replace backticks with Gitlab::Popen 2014-03-03 08:40:29 +01:00
Dmitriy Zaporozhets 54e40241f6 Merge branch 'backup_uploads_symlink' into 'master'
Backup Uploads Symlink
2014-03-01 12:55:13 +00:00
Jacob Vosmaer 75f274b750 Use Gitlab::VERSION to version backups
Previous to this commit, backups were tied to the git revision (SHA1) of
the app at the time the backup:create command was invoked. If the SHA1
at the time of restore was different, the script would refuse to restore
the backup.  This commit loosens this tie so that the backup script only
complains if the value of the Gitlab::VERSION constant is different
between the time of backup and the time of restore.
2014-02-27 14:30:41 +01:00
Dmitriy Zaporozhets 0a963ee15a Merge branch 'pg_force_restore' into 'master'
Pg Force Restore
2014-02-27 12:27:30 +00:00
Jacob Vosmaer 8fe10e642a Empty the database during Postgres backup restore
The expected behavior during a GitLab backup restore is to overwrite
existing database data. This works for MySQL because the output of
mysqldump contains 'DROP TABLE IF EXISTS' statements. pg_dump on the
other hand assumes that one will restore into an empty database. When
this is not the case, during the restore with psql some of the data will
be skipped if existing data is 'in the way'. By first invoking `rake
db:schema:load` during a Postgres GitLab backup restore, we make sure
that all important data is correctly restored.
2014-02-26 18:26:31 +01:00
Jacob Vosmaer 91c70c5b1c Use gitlab_shell.path to invoke rewrite-hooks.sh
The backup restore code for repositories was assuming that gitlab-shell
is installed in /home/git/gitlab-shell. This commit changes that to use
the configuration setting from gitlab.yml that specifies the path where
gitlab-shell is installed.
2014-02-26 17:32:52 +01:00
Jacob Vosmaer a47a6f2afd Support symlinked public/uploads for backp restore
The backup restore code moves any existing uploads directory out of the
way before restoring the copy from the backup. If public/uploads was a
symlink, this move would replace the symlink. This commit avoids this
issue by first resolving any symlinks in the uploads path.
2014-02-26 17:26:48 +01:00
Jacob Vosmaer 9e6fc8b526 Report failure of DB backup commands 2014-01-23 11:19:43 +01:00
Jacob Vosmaer 36f3de4f59 Remove duplication in Backup::Manager 2013-11-06 14:02:28 +01:00
Jacob Vosmaer a540ab4290 Remove Bourne shell from backup code 2013-11-06 14:02:28 +01:00