Use unique temporary location for copying backup files before they're tar'ed while creating backups with STRATEGY=copy option

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Proposal

Since we use generic names under backup location to copy temporary files before they're tar'ed, it's possible that two parallel backup create processes can collide each other and disrupt the tar process. This can either result in file changed as we read it error or the directory itself being removed by one process while the other process is reading it.

For example, repositories directory is used for copying git repos: https://gitlab.com/gitlab-org/gitlab/-/blob/0e619be609421b83f86a8779bfbd7323277c33e9/lib/backup/gitaly_rpc_backup.rb#L52. Simultaneous backup processes can write to the same repositories directory at the same time.

While this is a rare occurrence and there's no practical use case(at least I can't think of one) to run two backup processes simultaneously, I think having some kind of protection here will help.

My proposal is to use a unique temporary directory to copy such file, just like: https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/14.2.4+ee.0/files/gitlab-ctl-commands/lib/gitlab_ctl/backup.rb#L21.

Edited by 🤖 GitLab Bot 🤖