-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from nl2go/add-cronjob
Add cronjob for daily, weekly and monthly backups
- Loading branch information
Showing
13 changed files
with
125 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
- name: Check that clickhouse-backup cronjob file is created | ||
stat: | ||
path: "/etc/cron.d/clickhouse-backup-{{ item }}" | ||
register: stat_cronjob_result | ||
failed_when: not stat_cronjob_result.stat.exists | ||
loop: | ||
- daily | ||
- weekly | ||
- monthly | ||
|
||
- name: Run cronjob script | ||
command: /usr/local/bin/cronjob-clickhouse-backup-daily.sh | ||
register: cronjob_script_result | ||
run_once: yes | ||
|
||
- name: Verify cronjob script return code | ||
assert: | ||
that: | ||
- cronjob_script_result.rc == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
- name: Create clickhouse-backup cronjob bash script | ||
template: | ||
src: cronjob-clickhouse-backup.sh.j2 | ||
dest: "/usr/local/bin/cronjob-clickhouse-backup-{{ item }}.sh" | ||
owner: root | ||
group: root | ||
mode: '0775' | ||
loop: | ||
- daily | ||
- weekly | ||
- monthly | ||
|
||
- name: Set default state for clickhouse-backup cron file | ||
set_fact: | ||
clickhouse_backup_crontab_state: absent | ||
|
||
- name: Overwrite state for clickhouse-backup cron file | ||
set_fact: | ||
clickhouse_backup_crontab_state: present | ||
when: clickhouse_backup_install_crontab | ||
|
||
- name: Creates/remove cron file under /etc/cron.d | ||
cron: | ||
name: Add cronjob for clickhouse backup | ||
special_time: "{{ item }}" | ||
user: root | ||
job: "/usr/local/bin/cronjob-clickhouse-backup-{{ item }}.sh" | ||
cron_file: "clickhouse-backup-{{ item }}" | ||
state: "{{ clickhouse_backup_crontab_state }}" | ||
loop: | ||
- daily | ||
- weekly | ||
- monthly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
backup_name=`date -u +%Y-%m-%d` | ||
|
||
echo "Create {{ item }} local backup..." | ||
clickhouse-backup -c {{ clickhouse_backup_config_dir }}/config-{{ item }}.yml create $backup_name-{{ item }} | ||
|
||
echo "Upload {{ item }} full backup..." | ||
clickhouse-backup -c {{ clickhouse_backup_config_dir }}/config-{{ item }}.yml upload $backup_name-{{ item }} | ||
|
||
echo "Delete {{ item }} local backup..." | ||
clickhouse-backup -c {{ clickhouse_backup_config_dir }}/config-{{ item }}.yml delete local $backup_name-{{ item }} |