Last active
October 21, 2023 09:59
-
-
Save thorian93/69f19306c9cad44ce29711a2bc497dbc to your computer and use it in GitHub Desktop.
Revisions
-
thorian93 revised this gist
Feb 27, 2020 . 1 changed file with 16 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,9 @@ # # Version: 0.1 on 20191016 # Version: 0.2 on 20191017 # Version: 0.3 on 20191022 - Add cleanup routine and switch compression to bz2 # Version: 0.4 on 20191029 - Repair cleanup routine # Version: 1.0 on 20191107 - Change logfile to work with logrotate. Also bump version to 1.0 as the script works as intended. # # Usage: # ./backup-influxdb.sh @@ -16,7 +19,9 @@ influxdb_logfile="/var/log/backup/$(date +%Y%m%d_%H%M%S)_influx_backup.log" influxdb_databases='_internal' influxdb_host='localhost' influxdb_backup_root="/backup/influxdb" influxdb_backup_dest="${influxdb_backup_root}/$(date +%Y%m%d)/" influxdb_backup_retention="7" # Delete backups older than number of days # Functions: @@ -31,18 +36,26 @@ _influxdb_backup() { echo "$(date) Backing up ${influxdb_database}:" influxd backup -portable -database "${influxdb_database}" -host "${influxdb_host}:8088" "${influxdb_backup_dest}/${influxdb_database}" echo "$(date) Compressing Backup.." tar -caf "${influxdb_backup_dest}/${influxdb_database}.tar.bz2" "${influxdb_backup_dest}/${influxdb_database}" echo "$(date) Cleanup raw backup files.." rm -rf "${influxdb_backup_dest:?}/${influxdb_database}" echo "$(date) ${influxdb_database} done." done } _influxdb_cleanup() { echo 'Deleting old backups:' rm -rvf $(find ${influxdb_backup_root} -mtime +${influxdb_backup_retention}) echo "$(date) Cleanup done." } _finalize() { echo "$(date): Finished InfluxDB Backup." exit 0 } # Main _initialize >> "${influxdb_logfile}" 2>&1 _influxdb_backup >> "${influxdb_logfile}" 2>&1 _influxdb_cleanup >> "${influxdb_logfile}" 2>&1 _finalize >> "${influxdb_logfile}" 2>&1 -
thorian93 revised this gist
Oct 17, 2019 . No changes.There are no files selected for viewing
-
thorian93 created this gist
Oct 17, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ #!/bin/bash # # Written by: Robin Gierse - [email protected] - on 20191016 # # Purpose: # This script backs up influx databases # # Version: 0.1 on 20191016 # Version: 0.2 on 20191017 # # Usage: # ./backup-influxdb.sh # Variables: influxdb_logfile="/var/log/backup/$(date +%Y%m%d_%H%M%S)_influx_backup.log" influxdb_databases='_internal' influxdb_host='localhost' influxdb_backup_dest="/backup/influxdb/$(date +%Y%m%d)/" # Functions: _initialize() { echo "$(date): Starting InfluxDB Backup." touch "${influxdb_logfile}" } _influxdb_backup() { for influxdb_database in ${influxdb_databases} do echo "$(date) Backing up ${influxdb_database}:" influxd backup -portable -database "${influxdb_database}" -host "${influxdb_host}:8088" "${influxdb_backup_dest}/${influxdb_database}" echo "$(date) Compressing Backup.." tar -caf "${influxdb_backup_dest}/${influxdb_database}.tar.gz" "${influxdb_backup_dest}/${influxdb_database}" echo "$(date) Cleanup raw backup files.." rm -rf "${influxdb_backup_dest:?}/${influxdb_database}" echo "$(date) ${influxdb_database} done." done } _finalize() { echo "$(date): Finished InfluxDB Backup." } # Main _initialize >> "${influxdb_logfile}" 2>&1 _influxdb_backup >> "${influxdb_logfile}" 2>&1 _finalize >> "${influxdb_logfile}" 2>&1