Copy Gitlab backup files to an external drive by setting up crontab

Asked

Viewed 293 times

2

I set the server to run a cronjob and run the script that backs up Gitlab.

Gitlab in turn generates the files .tar in the briefcase var/opt/gitlab/backups

The first problem is that to access the folder mentioned above, I have to access using the sudo -i.

The second is that I need to configure crontab to sync the files in the folder var/opt/gitlab/backups to the external disk /media/<user>/usbbackup/.

How to configure crontab to perform the above action?

1 answer

2


You can add && rsync -a /var/opt/gitlab/backups/ /media/<user>/usbbackup to the crontab backup command. That way, when the backup is finished, the copy will be done. Make sure that the user running the crontab command has read and write permission in the directory.

You can also generate the backup directly in the desired directory by adding the option gitlab_rails['backup_path'] = '/media/<user>/usbbackup/' to the gitlab configuration file /etc/gitlab/gitlab.rb. Remember to run gitlab-ctl reconfigure after the change.

  • I tried this but error saying it is not allowed to write in the directory. What I really want is a copy of the files. tar and do not change directory. Thanks.

  • You can then add && rsync -a /var/opt/gitlab/backups/ /media/<user>/usbbackup crontab command. That way, when the backup finishes the copy will be done.

  • But to use the rsync I don’t need to use the sudo?

  • You do not need sudo. You only need permission to write and read in the directories with the user who is running the commands.

  • I executed the sudo -i to switch to the root account and only then can I run rsync manually. The question is: crontab runs as root?

  • By default yes. But it is possible to change the user and even ensure that it runs as root in this way: 0 0 * * * root rsync -a /var/opt/gitlab/backups/ /media/<user>/usbbackup. If you want to exchange the user replace the root by the desired user.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.