mirror of
https://github.com/fabianonline/telegram_backup.git
synced 2024-11-22 16:56:16 +00:00
Added a new database to track runs of this tool in order to be able to monitor them later on (Nagios, Icinga and so on).
This commit is contained in:
parent
70ee7566fd
commit
1c92f02422
@ -64,6 +64,7 @@ class Database {
|
||||
|
||||
private void init() {
|
||||
try {
|
||||
System.out.println("Opening database...");
|
||||
int version;
|
||||
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='database_versions'");
|
||||
rs.next();
|
||||
@ -122,13 +123,19 @@ class Database {
|
||||
}
|
||||
if (version==3) {
|
||||
System.out.println(" Updating to version 4...");
|
||||
stmt.executeUpdate("CREATE TABLE messages_new (id INTEGER PRIMARY KEY ASC, dialog_id INTEGER, to_id INTEGER, from_id INTEGER, from_type TEXT, text TEXT, time INTEGER, has_media BOOLEAN, sticker TEXT, data BLOB,type TEXT);");
|
||||
stmt.executeUpdate("CREATE TABLE messages_new (id INTEGER PRIMARY KEY ASC, dialog_id INTEGER, to_id INTEGER, from_id INTEGER, from_type TEXT, text TEXT, time INTEGER, has_media BOOLEAN, sticker TEXT, data BLOB, type TEXT);");
|
||||
stmt.executeUpdate("INSERT INTO messages_new SELECT * FROM messages");
|
||||
stmt.executeUpdate("DROP TABLE messages");
|
||||
stmt.executeUpdate("ALTER TABLE messages_new RENAME TO 'messages'");
|
||||
stmt.executeUpdate("INSERT INTO database_versions (version) VALUES (4)");
|
||||
version = 4;
|
||||
}
|
||||
if (version==4) {
|
||||
System.out.println(" Updating to version 5...");
|
||||
stmt.executeUpdate("CREATE TABLE runs (id INTEGER PRIMARY KEY ASC, time INTEGER, start_id INTEGER, end_id INTEGER, count_missing INTEGER)");
|
||||
stmt.executeUpdate("INSERT INTO database_versions (version) VALUES (5)");
|
||||
version = 5;
|
||||
}
|
||||
|
||||
System.out.println("Database is ready.");
|
||||
} catch (SQLException e) {
|
||||
@ -147,6 +154,19 @@ class Database {
|
||||
}
|
||||
}
|
||||
|
||||
public void logRun(int start_id, int end_id, int count) {
|
||||
try {
|
||||
PreparedStatement ps = conn.prepareStatement("INSERT INTO runs "+
|
||||
"(time, start_id, end_id, count_missing) "+
|
||||
"VALUES "+
|
||||
"(DateTime('now'), ?, ?, ? )");
|
||||
ps.setInt(1, start_id);
|
||||
ps.setInt(2, end_id);
|
||||
ps.setInt(3, count);
|
||||
ps.execute();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
|
||||
public int getMessageCount() {
|
||||
try {
|
||||
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM messages");
|
||||
|
@ -125,12 +125,14 @@ class DownloadManager {
|
||||
prog.onMessageDownloadFinished();
|
||||
}
|
||||
|
||||
int count_missing = 0;
|
||||
System.out.println("Checking message database for completeness...");
|
||||
if (db.getMessageCount() != db.getTopMessageID()) {
|
||||
if (limit != null) {
|
||||
System.out.println("You are missing messages in your database. But since you're using '--limit-messages', I won't download these now.");
|
||||
} else {
|
||||
LinkedList<Integer> ids = db.getMissingIDs();
|
||||
count_missing = ids.size();
|
||||
System.out.println("Downloading " + ids.size() + " messages that are missing in your database.");
|
||||
prog.onMessageDownloadStart(ids.size());
|
||||
while (ids.size()>0) {
|
||||
@ -149,6 +151,7 @@ class DownloadManager {
|
||||
prog.onMessageDownloadFinished();
|
||||
}
|
||||
}
|
||||
db.logRun(Math.min(max_database_id + 1, max_message_id), max_message_id, count_missing);
|
||||
}
|
||||
|
||||
public void downloadMedia() throws RpcErrorException, IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user