@@ -61,7 +61,7 @@ def dump_static
6161 if !@fu_conf [ :static_paths ]
6262 raise BackupFuConfigError , 'No static paths are defined in config/backup_fu.yml. See README.'
6363 end
64- paths = @fu_conf [ :static_paths ] . split ( ' ' ) ´
64+ paths = @fu_conf [ :static_paths ] . split ( ' ' )
6565 compress_static ( paths )
6666 end
6767
@@ -73,24 +73,30 @@ def backup_static
7373 puts "\n Backing up Static files to S3: #{ file } \n " if @verbose
7474
7575 AWS ::S3 ::S3Object . store ( File . basename ( file ) , open ( file ) , @fu_conf [ :s3_bucket ] , :access => :private )
76-
7776 end
78-
77+
7978 def cleanup
8079 count = @fu_conf [ :keep_backups ] . to_i
8180 backups = Dir . glob ( "#{ dump_base_path } /*.{sql}" )
8281 if count >= backups . length
8382 puts "no old backups to cleanup"
8483 else
8584 puts "keeping #{ count } of #{ backups . length } backups"
86-
85+
8786 files_to_remove = backups - backups . last ( count )
88- files_to_remove = files_to_remove . concat ( Dir . glob ( "#{ dump_base_path } /*.{gz}" ) [ 0 , files_to_remove . length ] ) unless @fu_conf [ :disable_compression ]
89-
87+
88+ if ( !@fu_conf [ :disable_compression ] )
89+ if ( @fu_conf [ :compressor ] == 'zip' )
90+ files_to_remove = files_to_remove . concat ( Dir . glob ( "#{ dump_base_path } /*.{zip}" ) [ 0 , files_to_remove . length ] )
91+ else
92+ files_to_remove = files_to_remove . concat ( Dir . glob ( "#{ dump_base_path } /*.{gz}" ) [ 0 , files_to_remove . length ] )
93+ end
94+ end
95+
9096 files_to_remove . each do |f |
9197 File . delete ( f )
9298 end
93-
99+
94100 end
95101 end
96102
@@ -135,30 +141,46 @@ def dump_base_path
135141 def db_filename
136142 "#{ @fu_conf [ :app_name ] } _#{ @timestamp } _db.sql"
137143 end
138-
144+
139145 def db_filename_compressed
140- db_filename . gsub ( '.sql' , '.tar' )
146+ if ( @fu_conf [ :compressor ] == 'zip' )
147+ db_filename . gsub ( '.sql' , '.zip' )
148+ else
149+ db_filename . gsub ( '.sql' , '.tar' )
150+ end
141151 end
142-
152+
143153 def final_db_dump_path
144- if @fu_conf [ :disable_compression ]
154+ if ( @fu_conf [ :disable_compression ] )
145155 filename = db_filename
146156 else
147- filename = db_filename . gsub ( '.sql' , '.tar.gz' )
157+ if ( @fu_conf [ :compressor ] == 'zip' )
158+ filename = db_filename . gsub ( '.sql' , '.zip' )
159+ else
160+ filename = db_filename . gsub ( '.sql' , '.tar.gz' )
161+ end
148162 end
149163 File . join ( dump_base_path , filename )
150164 end
151-
165+
152166 def static_compressed_path
153- f = "#{ @fu_conf [ :app_name ] } _#{ @timestamp } _static.tar"
167+ if ( @fu_conf [ :compressor ] == 'zip' )
168+ f = "#{ @fu_conf [ :app_name ] } _#{ @timestamp } _static.zip"
169+ else
170+ f = "#{ @fu_conf [ :app_name ] } _#{ @timestamp } _static.tar"
171+ end
154172 File . join ( dump_base_path , f )
155173 end
156-
174+
157175 def final_static_dump_path
158- f = "#{ @fu_conf [ :app_name ] } _#{ @timestamp } _static.tar.gz"
176+ if ( @fu_conf [ :compressor ] == 'zip' )
177+ f = "#{ @fu_conf [ :app_name ] } _#{ @timestamp } _static.zip"
178+ else
179+ f = "#{ @fu_conf [ :app_name ] } _#{ @timestamp } _static.tar.gz"
180+ end
159181 File . join ( dump_base_path , f )
160182 end
161-
183+
162184 def create_dirs
163185 ensure_directory_exists ( dump_base_path )
164186 end
@@ -180,17 +202,24 @@ def datetime_formatted
180202 end
181203
182204 def compress_db ( dump_base_path , db_filename )
183- tar_path = File . join ( dump_base_path , db_filename_compressed )
205+ compressed_path = File . join ( dump_base_path , db_filename_compressed )
184206
185- # TAR it up
186- cmd = niceify "tar -cf #{ tar_path } -C #{ dump_base_path } #{ db_filename } "
187- puts "\n Tar: #{ cmd } \n " if @verbose
188- `#{ cmd } `
207+ if ( @fu_conf [ :compressor ] == 'zip' )
208+ cmd = niceify "zip #{ compressed_path } #{ dump_base_path } /#{ db_filename } "
209+ puts "\n Zip: #{ cmd } \n " if @verbose
210+ `#{ cmd } `
211+ else
189212
190- # GZip it up
191- cmd = niceify "gzip -f #{ tar_path } "
192- puts "\n Gzip: #{ cmd } " if @verbose
193- `#{ cmd } `
213+ # TAR it up
214+ cmd = niceify "tar -cf #{ compressed_path } -C #{ dump_base_path } #{ db_filename } "
215+ puts "\n Tar: #{ cmd } \n " if @verbose
216+ `#{ cmd } `
217+
218+ # GZip it up
219+ cmd = niceify "gzip -f #{ compressed_path } "
220+ puts "\n Gzip: #{ cmd } " if @verbose
221+ `#{ cmd } `
222+ end
194223 end
195224
196225 def compress_static ( paths )
@@ -202,23 +231,30 @@ def compress_static(paths)
202231 end
203232
204233 puts "Static Path: #{ p } " if @verbose
205- if path_num == 0
206- tar_switch = 'c' # for create
234+
235+ if @fu_conf [ :compressor ] == 'zip'
236+ cmd = niceify "zip -r #{ static_compressed_path } #{ p } "
237+ puts "\n Zip: #{ cmd } \n " if @verbose
238+ `#{ cmd } `
207239 else
208- tar_switch = 'r' # for append
209- end
240+ if path_num == 0
241+ tar_switch = 'c' # for create
242+ else
243+ tar_switch = 'r' # for append
244+ end
210245
211- # TAR
212- cmd = niceify "tar -#{ tar_switch } f #{ static_compressed_path } #{ p } "
213- puts "\n Tar: #{ cmd } \n " if @verbose
214- `#{ cmd } `
246+ # TAR
247+ cmd = niceify "tar -#{ tar_switch } f #{ static_compressed_path } #{ p } "
248+ puts "\n Tar: #{ cmd } \n " if @verbose
249+ `#{ cmd } `
215250
216- path_num += 1
217- end
251+ path_num += 1
218252
219- # GZIP
220- cmd = niceify "gzip -f #{ static_compressed_path } "
221- puts "\n Gzip: #{ cmd } " if @verbose
222- `#{ cmd } `
253+ # GZIP
254+ cmd = niceify "gzip -f #{ static_compressed_path } "
255+ puts "\n Gzip: #{ cmd } " if @verbose
256+ `#{ cmd } `
257+ end
258+ end
223259 end
224260end
0 commit comments