Browse Source

Add a CLI option to disable cleanups (with examples)

master
Timur Demin 1 month ago
parent
commit
3ab4884c8c
Signed by: Timur Demin <me@tdem.in> GPG Key ID: 9EDF3F9D9286FA20
3 changed files with 15 additions and 7 deletions
  1. 1
    0
      README.md
  2. 13
    6
      backup.sh
  3. 1
    1
      systemd/backup_postgresql.service

+ 1
- 0
README.md View File

@@ -27,6 +27,7 @@ It comes with example systemd units/timers made to do just that.
27 27
     -p | --postgres: run the backups on PostgreSQL databases
28 28
     -d | --docker: run the backups on Docker volumes
29 29
     -c | --configs: run the backups on the files specified in /etc/backups.conf
30
+    --no-cleanup: don't cleanup after the backup has finished
30 31
 
31 32
 ##### Configuration options
32 33
 

+ 13
- 6
backup.sh View File

@@ -102,6 +102,7 @@ Options:
102 102
 -p | --postgres: run the backups on PostgreSQL databases
103 103
 -d | --docker: run the backups on Docker volumes
104 104
 -c | --configs: run the backups on the files specified in /etc/backups.conf
105
+--no-cleanup: don't cleanup after the backup has finished
105 106
 EOF
106 107
 }
107 108
 
@@ -115,6 +116,7 @@ case ${1} in
115 116
         ;;
116 117
     "-h" | "--help")
117 118
         print_help
119
+        __BACKUP_NO_CLEANUP=1 # prevent cleanup on displaying help
118 120
         ;;
119 121
     *)
120 122
         while [[ ! -z ${1} ]]; do
@@ -128,15 +130,20 @@ case ${1} in
128 130
                 "-c" | "--configs")
129 131
                     backup_configs
130 132
                     ;;
133
+                "--no-cleanup")
134
+                    __BACKUP_NO_CLEANUP=1
135
+                    ;;
131 136
             esac
132 137
             shift
133 138
         done
134 139
         ;;
135 140
 esac
136 141
 
137
-echo "Cleaning up..."
138
-# Run cleanup on every backup directory.
139
-for i in ${__BACKUP_DIR} ${__BACKUP_DIR_CONFIGS} ${__BACKUP_DIR_DOCKER} \
140
-    ${__BACKUP_DIR_POSTGRES}; do
141
-    [[ ! -z $i ]] && clean_up $i
142
-done
142
+if [[ -z ${__BACKUP_NO_CLEANUP} ]]; then
143
+    echo "Cleaning up..."
144
+    # Run cleanup on every backup directory.
145
+    for i in ${__BACKUP_DIR} ${__BACKUP_DIR_CONFIGS} ${__BACKUP_DIR_DOCKER} \
146
+        ${__BACKUP_DIR_POSTGRES}; do
147
+        [[ ! -z $i ]] && clean_up $i
148
+    done
149
+fi

+ 1
- 1
systemd/backup_postgresql.service View File

@@ -3,7 +3,7 @@ Description=Run backups on PostgreSQL databases
3 3
 
4 4
 [Service]
5 5
 Type=oneshot
6
-ExecStart=/usr/local/bin/backup.sh -p
6
+ExecStart=/usr/local/bin/backup.sh -p --no-cleanup
7 7
 User=postgres
8 8
 Group=postgres
9 9
 WorkingDirectory=/tmp

Loading…
Cancel
Save