Skip to content

Commit

Permalink
SVCPLAN-5526: Convert backup class to use parameters to can be overwr…
Browse files Browse the repository at this point in the history
…itten
  • Loading branch information
billglick committed May 23, 2024
1 parent c0bdbe5 commit 98bc792
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
26 changes: 26 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ Configure GitLab backups
include profile_gitlab::backup
```

#### Parameters

The following parameters are available in the `profile_gitlab::backup` class:

* [`paths`](#-profile_gitlab--backup--paths)
* [`prehook_commands`](#-profile_gitlab--backup--prehook_commands)
* [`posthook_commands`](#-profile_gitlab--backup--posthook_commands)

##### <a name="-profile_gitlab--backup--paths"></a>`paths`

Data type: `Array[String]`

List of paths (locations to files or directories) to be backed up.

##### <a name="-profile_gitlab--backup--prehook_commands"></a>`prehook_commands`

Data type: `Array[String]`

List of commands to run before the paths are backed up.

##### <a name="-profile_gitlab--backup--posthook_commands"></a>`posthook_commands`

Data type: `Array[String]`

List of commands to run after the paths are backed up.

### <a name="profile_gitlab--firewall"></a>`profile_gitlab::firewall`

Open GitLab ports in the firewall
Expand Down
8 changes: 8 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
---
profile_gitlab::backup::paths:
- "/etc/gitlab"
- "/var/opt/gitlab/backups"
profile_gitlab::backup::prehook_commands:
- "/opt/gitlab/bin/gitlab-backup create CRON=1"
profile_gitlab::backup::posthook_commands:
- "find /etc/gitlab/config_backup \\( -name '*.tar' \\) -mtime +30 -type f -exec rm -rf {} \\;"
- "find /var/opt/gitlab/backups \\( -name '*.tar' \\) -mtime +2 -type f -exec rm -rf {} \\;"
profile_gitlab::firewall::http_allowed_subnets:
"public": "0.0.0.0/0"
#"NCSA private": "172.24.0.0/13"
Expand Down
38 changes: 17 additions & 21 deletions manifests/backup.pp
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
# @summary Configure GitLab backups
#
# @param paths
# List of paths (locations to files or directories) to be backed up.
#
# @param prehook_commands
# List of commands to run before the paths are backed up.
#
# @param posthook_commands
# List of commands to run after the paths are backed up.
#
# @example
# include profile_gitlab::backup
class profile_gitlab::backup {
class profile_gitlab::backup (
Array[String] $paths,
Array[String] $prehook_commands,
Array[String] $posthook_commands,
) {
if ( lookup('profile_backup::client::enabled') ) {
include profile_backup::client

profile_backup::client::add_job { 'profile_gitlab':
paths => [
'/etc/gitlab',
'/var/opt/gitlab/backups',
],
prehook_commands => [
'/opt/gitlab/bin/gitlab-backup create CRON=1',
],
posthook_commands => [
"find /etc/gitlab/config_backup \\( -name '*.tar' \\) -mtime +30 -type f -exec rm -rf {} \\;",
"find /var/opt/gitlab/backups \\( -name '*.tar' \\) -mtime +2 -type f -exec rm -rf {} \\;",
],
}

# REMOVE OLD BACKUP CRONS FROM <= v0.1.1 OF THIS MODULE
# THIS LOGIC CAN BE REMOVED IN FUTURE VERSIONS OF THIS MODULE
cron { 'GITLAB DAILY BACKUPS':
ensure => 'absent',
}
cron { 'GITLAB CLEANUP BACKUPS':
ensure => 'absent',
paths => $paths,
prehook_commands => $prehook_commands,
posthook_commands => $posthook_commands,
}
}
}

0 comments on commit 98bc792

Please sign in to comment.