backend-manager 2.5.106 → 2.5.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -289,37 +289,43 @@ Module.prototype._deleteOldFiles = function (bucketName, resourceZone) {
|
|
|
289
289
|
// get the file names as an array
|
|
290
290
|
let [allFiles] = await storage.bucket(bucketName).getFiles();
|
|
291
291
|
allFiles = allFiles.map(file => file.name);
|
|
292
|
-
|
|
292
|
+
|
|
293
|
+
assistant.log(`All files: ${allFiles.join(', ')}`);
|
|
293
294
|
|
|
294
295
|
// transform to array of objects with creation timestamp { fileName: xyz, created: }
|
|
295
296
|
allFiles = allFiles.map(fileName => getFileObjectWithMetaData(bucketName, fileName));
|
|
296
297
|
allFiles = await Promise.all(allFiles);
|
|
297
298
|
|
|
298
|
-
|
|
299
299
|
const filesToKeep = new Set(); // using set insted of array since set does not allow duplicates
|
|
300
300
|
|
|
301
301
|
// recent backups
|
|
302
302
|
allFiles.forEach(backup => {
|
|
303
303
|
const createdDate = new Date(backup.created);
|
|
304
304
|
createdDate.setHours( createdDate.getHours() + numHoursToKeepRecentBackups );
|
|
305
|
-
|
|
305
|
+
|
|
306
|
+
if (createdDate > new Date()) {
|
|
307
|
+
filesToKeep.add(backup.fileName)
|
|
308
|
+
};
|
|
306
309
|
})
|
|
307
310
|
|
|
308
311
|
// daily backups
|
|
309
|
-
for(var i = 0; i < numDaysToKeepOneDailyBackup; i++) {
|
|
312
|
+
for (var i = 0; i < numDaysToKeepOneDailyBackup; i++) {
|
|
310
313
|
// get day
|
|
311
314
|
const now = new Date();
|
|
312
315
|
now.setDate( now.getDate() - i );
|
|
313
316
|
dateString = now.toISOString().substring(0, 10);
|
|
314
317
|
// keep only one from that day
|
|
315
318
|
const backupsFromThatDay = allFiles.filter(backup => backup.created.startsWith(dateString));
|
|
316
|
-
if(backupsFromThatDay && backupsFromThatDay.length > 0)
|
|
319
|
+
if (backupsFromThatDay && backupsFromThatDay.length > 0) {
|
|
320
|
+
filesToKeep.add(backupsFromThatDay[0].fileName)
|
|
321
|
+
};
|
|
317
322
|
}
|
|
318
323
|
|
|
319
324
|
// filesToKeep.forEach(item => console.log(item));
|
|
320
325
|
|
|
321
326
|
const filesToDelete = allFiles.filter(backup => !filesToKeep.has(backup.fileName));
|
|
322
|
-
|
|
327
|
+
|
|
328
|
+
assistant.log(`Deleting ${filesToDelete.length} files: ${filesToDelete.map(backup => backup.fileName).join(', ')}`);
|
|
323
329
|
|
|
324
330
|
const deletePromises = filesToDelete.map(backup => deleteFileFromBucket(bucketName, backup.fileName));
|
|
325
331
|
await Promise.all(deletePromises);
|