public void BackupDatabase(string dest) { SQLiteConnection backupCon = null; if (dest.StartsWith(@"\\")) { backupCon = new SQLiteConnection(string.Format("Data Source={0};Compress=True;UTF8Encoding=True;", dest), true); } else { new SQLiteConnection(string.Format("Data Source={0};Compress=True;UTF8Encoding=True;", dest)); } backupCon.Open(); SQLCon.Open(); SQLCon.BackupDatabase(backupCon, backupCon.Database, SQLCon.Database, -1, null, -1); SQLCon.Close(); backupCon.Close(); backupCon.Dispose(); // delete old logs - we have them in the backup which got created using (SQLiteCommand delCmd = new SQLiteCommand("DELETE FROM LOGGING WHERE Timestamp <= date('now', '-30 day'); VACUUM;", SQLCon)) { SQLCon.Open(); delCmd.ExecuteNonQuery(); SQLCon.Close(); } }