Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Error: database is locked #161

Closed
Dart353 opened this issue Nov 20, 2023 · 4 comments
Closed

SQL Error: database is locked #161

Dart353 opened this issue Nov 20, 2023 · 4 comments

Comments

@Dart353
Copy link

Dart353 commented Nov 20, 2023

Hello,
I am trying to integrate your signalbackup-tools.exe with my current project.

I have encountered some issues when using the -o argument when running the command in WSL and having it save to a file in my repo. --exporthtml, --exporttext both work fine running through WSL

I am receiving the following error when using -o:

$ ts-node ./src/scripts/readDatabase.ts

signalbackup-tools (signalbackup-tools_win.exe) source version 20231107.231353 (Win)
BACKUPFILE VERSION: 1
BACKUPFILE SIZE: 14356599
COUNTER: 1693877385
Reading backup file...
FRAME 1225 (100.0%)... Read entire backup file...

done!
Database version: 209

Exporting backup into '/output/'
Clearing contents of directory '/output'...
Writing HeaderFrame...
Writing DatabaseVersionFrame...
Writing Attachments...
Writing Avatars...
Writing SharedPrefFrame(s)...
Writing KeyValueFrame(s)...
Writing StickerFrames...
Writing EndFrame...
Writing database...
SQL Error: database is locked
SQL Error: Error finishing backup
Error exporting sqlite database
Error: Failed to export backup to '/output'

This is what my code looks like:

import sqlite3 from 'sqlite3';
import path from 'path';
import {readFileSync} from "fs";
import {readdir} from "fs/promises";
import {execFile, exec} from "child_process";



async function readBackUpFile() {
    const exePath = path.resolve(__dirname, './signalbackup-tools_win.exe');
    const outputPath = path.resolve(__dirname, './output');
    const backupsPath = path.resolve(__dirname, './backups/signal-2023-11-14-11-02-38.backup');

    const command = `${exePath} ${backupsPath} BACKUP-PIN-HERE -o ${outputPath} --overwrite`

    try {
        await executeCommand(command);
        console.log("finished")
    } catch (e) {
        console.log(e);
    }
    process.exit();
}

function executeCommand(command: string) {
    return new Promise((resolve, reject) => {
        exec(command,(error, stdout, stderr) => {
            if (error) {
                reject(error);
            }
            console.error(stderr);
            console.log(stdout);
            return resolve;
        });
    });
}

I am running:
WSL Version: Ubuntu-20.04
Nodejs: 18.11.0

@bepaald
Copy link
Owner

bepaald commented Nov 21, 2023

I believe you are running into a bug in WSL (most probably microsoft/WSL#4689).

The code as you posted it works fine, I tested it on Linux natively. I am currently unable to test on Windows, as I only have Windows on a VM that refuses to install WSL (hence the late reply, though I'm trying to fix that).

If running the exact same binary with the same input and arguments on Windows directly (without WSL) works, the problem is WSL. If you get the same error in this case, please let me know.

Having said that, why are you running this in WSL anyway, I see no Linux specific commands anywhere? Couldn't you just write a Windows batch script to do the same task?

Thanks!

@bepaald
Copy link
Owner

bepaald commented Nov 24, 2023

I've had to give up trying to get WSL working on VM, so I can't reproduce your exact problem.

I am going to close this issue, as I'm pretty much 100% sure this is not my bug. If you have any reason to believe this problem is indeed in my program and not in Windows (subsystem for Linux) feel free to reopen this.

Thanks!

@bepaald bepaald closed this as completed Nov 24, 2023
@Dart353
Copy link
Author

Dart353 commented Dec 6, 2023

Hey @bepaald, Sorry I took a minute to respond.

I was able to get this to work with WSL. I was just missing an updated version of lsqlite3... A silly mistake on my side.

Thank you so much for your assistance though.

I have some general questions about how I can compile data a bit more efficiently though:
For example:
When I run the command:

${exePath} ${backupsPath} BACKUP-PIN-HERE -o ${outputPath} --overwrite

This will dump out a lot of data into a file. Which by the looks of it is a lot of media/attachements/avatars.

What I am trying to do is correspond these items with what I am seeing on the database.sqlite file.

Like, How can I correlate "recipient" with their proper avatar? As well as, attachments to proper messages?

I have seen that this is possible with the --exporthtml argument. Is it possible with the -o output?

@bepaald
Copy link
Owner

bepaald commented Dec 6, 2023

Hey @bepaald, Sorry I took a minute to respond.

I was able to get this to work with WSL. I was just missing an updated version of lsqlite3... A silly mistake on my side.

Thank you so much for your assistance though.

Can't say I fully understand, the Windows binary (which according to your script you are using), is a static build, it contains all the required sqlite functions. It can and does run without having sqlite3 installed at all. So i don't know how updating it affects this program at all. But, you got it working, so that's fine.

What I am trying to do is correspond these items with what I am seeing on the database.sqlite file.

Like, How can I correlate "recipient" with their proper avatar? As well as, attachments to proper messages?

For avatars: They have a number called "RECIPIENT", this number is visible inside the .sbf file (these are just plain text files) but also the last number in the filename. This number corresponds to the _id column of the recipient table in the database, which identifies the recipient the avatar belongs to.

For attachments: These have two numbers, named "ROWID" and "ATTACHMENTID", again visible in the .sbf file, but also the two numbers in the filename. These correspond to the _id and unique_id columns in the part table of the database. For each attachment exactly 1 row in the part table will match these two numbers, this row will also have a mid column whose value corresponds to an _id in the message table (or mms table in older databases), which identifies the message the attachment belongs to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants