fix empty backups
[BackupPC.git] / sql / zz_fix_empty_backups.sql
diff --git a/sql/zz_fix_empty_backups.sql b/sql/zz_fix_empty_backups.sql
new file mode 100644 (file)
index 0000000..bc3a159
--- /dev/null
@@ -0,0 +1,16 @@
+begin;
+
+-- make temporary table with all backup ids
+select backups.id into temporary all_backup_ids from files
+join shares on files.shareid = shares.id
+join backups on backups.hostid = shares.hostid and backups.num = files.backupnum
+where files.shareid = shares.id
+group by backups.id, files.shareid, files.backupnum
+;
+
+-- fix backups which are deleted and have size anyway 
+update backups set inc_deleted = false where id not in (select id from all_backup_ids) and size > 0 ;
+
+-- fix parts numbering
+
+update backups set parts = 0 where parts > 0 and id not in (select backup_id from backup_parts) ;