lost ipython history - database locked - sqlite

Was playing with ipython history commands, experimenting with combining -l and -g to search a limited amount of history, and using -n to see which session a command came from.
Suddenly I got an error (I wish I still had the exact text on my screen) ... something about the history thread encountered and error and stopped, and no more history would be saved. And it said also something about "database locked". After that happened, %history would not recall any history.
So I stopped and restarted ipython, and found that it had history only from the newly restarted session. I stopped and restarted again, and even tried closing and reopening my WSL-Ubuntu window with no luck. It appears that I lost months and months of history.
Then I decided to look for the ipython history file, and found this little gem:
dino#DINO:~$ ls -l $( ipython locate profile default )
total 14132
drwxrwxrwx 1 dino dino 512 Jul 17 2019 db
-rw-r--r-- 1 dino dino 14442496 Mar 24 14:16 history-corrupt-2020-03-24T14.17.27.480963.sqlite
-rw-r--r-- 1 dino dino 28672 Mar 24 14:24 history.sqlite
drwxrwxrwx 1 dino dino 512 Mar 18 2019 log
drwx------ 1 dino dino 512 Mar 18 2019 pid
drwx------ 1 dino dino 512 Mar 18 2019 security
drwxrwxrwx 1 dino dino 512 Mar 18 2019 startup
Wow! Look at that! 14442496 Mar 24 14:16 history-corrupt-2020-03-24T14.17.27.480963.sqlite
Looks like ipython actually saved all that history after all! Now the question is, does anyone have any ideas how I might find and remove the corruption from the sqlite file and restore all or maybe most of my history??

Yay, I fixed it! So here's what I did. With some googling I found this program called "sqlitebrowser" and I found this other page with a section titled "How to Repair SQLite database?" that explained that you can sometimes fix an SQLite database by exporting the database to an SQL file, and then importing the SQL file to create a new version of the database.
So I tried that but, when I imported the SQL file, I got an error saying that it failed due to a UNIQUE constraint on the "sessions" table, and that it was unwinding the transaction.
Unfortunately, when I had done the export to SQL, I chose the option to group the inserts into as few SQL commands as possible, so the unwind undid the entire "sessions" table. I later realized that if I had not grouped the inserts, maybe that import would have fixed the database (simply failing on those transactions that contained duplicate sessions).
However at that time, I was not yet sure what was going on and didn't think to go back and re-export to regenerate the SQL with lots of individual inserts.
Instead, I chose to look through the SQL file for any duplicate inserts on the "sessions" table. Indeed, with some sed and sort commands (sort vs sort -u, followed by diff), I was able to determine that sessions 227 through 236 where somehow in there twice!
So I deleted the duplicates from the SQL file, and then again used sqlitebrowser to import the SQL file and re-create the IPython history.sqlite file. I then ran ipython and found that %history magic was able once again to access all my history.
Please let me know with a comment and/or a up-vote if this answer is helpful to anyone. All the best.

Related

sqlite not opening db file on local drive

I've recently upgraded to a new M1 running Monterey. My existing sqlite db files exist on an external drive and I can access them with Perl via DBI. But when I copy the .db files to my local internal drive, sqlite is not able to open them.
$dbh=DBI->connect('dbi:SQLite:dbname=/Users/trudge/MyDB/kb.db','','') or die $DBI::errstr;
throws this error:
DBI connect('dbname=/Users/trudge/MyDB/kb.db','',...) failed: unable to open database file at /Users/trudge/http/cgi-bin/kb/index.pl line 74.
unable to open database file at /Users/trudge/http/cgi-bin/kb/index.pl line 74.
I've recompiled sqlite3 (SQLite version 3.38.1 2022-03-12 13:37:29) but still no joy.
Not sure if this is a DBI problem, or an sqlite problem, or an Apple problem. Apparently the DBI supports sqlite 3.3 which should not be an issue.
Permission & ACL:
-rwxrw-rw- 1 trudge staff 102400 Mar 10 12:20 ephemera.db
-rw-rw-rw-# 1 trudge staff 458752 Mar 5 17:19 kb.db
-rwxrw-rw- 1 trudge staff 90112 Mar 10 12:20 kba.db
-rwxrw-rw- 1 trudge staff 262144 Mar 10 12:20 library.db
-rwxrw-rw- 1 trudge staff 1630208 Mar 7 20:13 tunes3.db
I would appreciate any advice or suggestions as to why this is an issue and how I might solve it.
Such a simple solution. I checked permissions on my remote site (hosted) for the DB files. The directory was 755. My local system was not. Once I made the changes locally I finally had access to all the sqlite db files.
Apologies for such a newb oversight. Maybe I should retire from this.

fsck finds Multiply-claimed block(s) and files are shared with badblock inode #1

I have an LVM hard drive. It holds all my media for use by Kodi. It occasionally (about once a week) cannot access the media. Attempting to remount the device with sudo mount -a resulted in Input/Output error.
The solution from various sources was that it contains badblocks so I have run fsck -cc /dev/icybox/media to do a non-destructive read-write badblocks check.
It took 5 days but finally it finished, good news, no read or write errors but a couple of hundred corrupted blocks.
Here is some of the output:
# fsck -cc -V /dev/icybox/media
fsck from util-linux 2.34
[/usr/sbin/fsck.ext4 (1) -- /mnt/icybox] fsck.ext4 -cc /dev/mapper/icybox-media
e2fsck 1.45.5 (07-Jan-2020)
Checking for bad blocks (non-destructive read-write test)
Testing with random pattern: done
/dev/mapper/icybox-media: Updating bad block inode.
Pass 1: Checking inodes, blocks, and sizes
Running additional passes to resolve blocks claimed by more than one inode...
Pass 1B: Rescanning for multiply-claimed blocks
Multiply-claimed block(s) in inode 55640069: 849596509
Multiply-claimed block(s) in inode 55640261: 448514694
Multiply-claimed block(s) in inode 55641058: 465144485
Multiply-claimed block(s) in inode 55641147: 470406248
...and lots more Multiply-claimed block(s)
Then this:
Pass 1C: Scanning directories for inodes with multiply-claimed blocks
Pass 1D: Reconciling multiply-claimed blocks
(There are 190 inodes containing multiply-claimed blocks.)
File /TV Shows/Arrested Development/Arrested Development - Season 1/Arrested Development - 119 - Best Man for the Gob.mkv (inode #55640069, mod time Sat May 5 11:19:03 2018)
has 1 multiply-claimed block(s), shared with 1 file(s):
<The bad blocks inode> (inode #1, mod time Thu May 20 22:36:40 2021)
Clone multiply-claimed blocks<y>? yes
There are a bunch more files saying they have 1 multiply-claimed blocks shared with 1 file on inode #1. Should I say yes to the clone question?
All the files shown are shared with bad block inode #1, according to https://unix.stackexchange.com/questions/198673/why-does-have-the-inode-2 inode#1 stores the badblocks.
So I have a bunch of question:
How can this file be shared with badblocks?
Is the badblocks list incorrect/corrupted?
Is there a way to clear the badblocks list and do another scan to start over to fill it correctly?
I am not too bothered about losing the data of individual media files so long as I can take a list to re-download them.
P.S. Not sure if it is relevant, I had run the same fsck command before this and it was interrupted by a power outage so I don't know if that would cause a corrupted badblock inode #1.
I ran it another time which got to about 70% and then something went wrong and every block was becoming a read error (I think it became Input/Output error again) so I am worried all those blocks were listed as badblocks, I cancelled the process when I noticed it at about 70% so it didn't finish.
Thanks for any help and answers

Fuseki configuration

As outlined in http://wiki.bitplan.com/index.php/Apache_Jena#Script_to_start_Fuseki_server
I have been avoiding the complexity of Fuseki configuration files and started the server from a script for my usecases in which I only need one dataset/endpoint. For multiple datasets/endpoints i simply used multiple servers.
Descriptions like:
https://jena.apache.org/documentation/fuseki2/fuseki-config-endpoint.html
and questions like:
fuseki Multiple services found exception
have been intimidating me since there seem to be so many options and no straight forward way to simply say: please use these dataset from the following directories as the command line version can do for one dataset.
Just look at:
https://users.jena.apache.narkive.com/MNZHLT25/multiple-datasets-on-fuseki
where the user expectation:
java -jar fuseki-0.1.0-server.jar --update --loc=data /dataset
--loc=data2 /dataset2
can be seen that is unfortunately not fullfilled. Instead:
http://jena.apache.org/documentation/serving_data/index.html#fuseki-configuration-file
was the answer at the time which is now an outdated link.
So obviously there are people out there getting fuseki to work with multiple datasets. But how do they do it ?
I know how to load a TDB store from a triple file via command line. I know that i could use the WebGUI to setup datasets and load data but that won't work for my multi million (and partly multi-billion) triple files.
What is a (hopefully simple) example for loading multiple triple files and making the result available with the same fuseki server as different datasets and have the SPARQL endpoints running (partly read-only?)
https://jena.apache.org/documentation/fuseki2/fuseki-layout.html gives a hint on the layout of files.
Using the script to start fuseki i inspected the run directory which in my case was to be found at:
apache-jena-fuseki-3.16.0/run
There are two subdirectories which are initially empty and stay so if you run things from the commandline:
configuration
database
By adding a dataset via the webgui http://localhost:3030
a directory with the name of the dataset in this case:
databases/cr
and a configuration file
configuration/cr.ttl
is created.
For smaller datasets data can now be added via the webgui. For bigger datasets a copy or symlink of the original loaded tdb data is necessary in the databases directory.
example symlinks:
zeus:databases wf$ls -l
total 48
drwxr-xr-x 4 wf admin 136 Sep 14 07:43 cr
lrwxr-xr-x 1 wf admin 27 Sep 15 11:53 dblp -> /Volumes/Torterra/dblp/data
lrwxr-xr-x 1 wf admin 26 Sep 14 08:10 gnd -> /Volumes/Torterra/gnd/data
lrwxr-xr-x 1 wf admin 42 Sep 14 07:55 wikidata -> /Volumes/Torterra/wikidata2020-08-15/data/
By restarting the server without a --loc
nohup java -jar fuseki-server.jar&
the configurations are automatically picked up.
The good news is that you do not have to bother with the details of the config files this way as long as you do not have any special needs.

DllNotFound: FirebaseCppApp-6_14_0 on Android only?

I am currently using Unity to create my game, and I am implementing the user account system now. The send/receive methods for username/password work perfectly fine in Editor, but when I build on Android, logcat gives me the error in the question title (DllNotFound).
Obviously the DLL is not missing, yes? Otherwise it wouldn't work on standalone desktop/Editor? If this is the case, I am assuming it isn't getting built into the Unity .apk for whatever reason. Does anyone have any reason why? I haven't found any useful resources online, as all the similar questions I have run across are regarding no functionality at all, not split functionality across platforms.
What reasons would Unity recognize a DLL in Editor/standalone, but not on an Android build?
(The .dll in question is located at \Assets\Firebase\Plugins\x86_64, if that helps).
Your fix is probably to run force resolve in the Android resolver.
Which should give you the file you need as part of firebase-app-unity:
My reasoning:
The Unity SDK actually ships with roughly five copies of each native library for iOS, Android, MacOS, Windows, and Linux (plus variants for different architectures &c). The FirebaseCppApp libraries being C++ implementations of some Firebase features. If you look in the folder you listed, you'll see a bunch of library folders for different editor platforms:
╰─$ ls -al | fgrep -v .meta
total 558360
drwxr-xr-x# 14 martinpatrick primarygroup 448 May 8 10:06 .
drwxr-xr-x 25 martinpatrick primarygroup 800 May 8 10:18 ..
-rwxrwxr-x# 1 martinpatrick primarygroup 48236 Dec 4 2016 FirebaseCppAnalytics.bundle
-rwxrwxr-x# 1 martinpatrick primarygroup 355840 Dec 4 2016 FirebaseCppAnalytics.dll
-rwxrwxr-x# 1 martinpatrick primarygroup 226136 Dec 4 2016 FirebaseCppAnalytics.so
-rwxrwxr-x# 1 martinpatrick primarygroup 23186972 Dec 4 2016 FirebaseCppApp-6_14_0.bundle
-rwxrwxr-x# 1 martinpatrick primarygroup 7526400 Dec 4 2016 FirebaseCppApp-6_14_0.dll
-rwxrwxr-x# 1 martinpatrick primarygroup 254502608 Dec 4 2016 FirebaseCppApp-6_14_0.so
bundle is for OSX, dll is for Windows, and so is for Linux.
Clearly this is missing the iOS and Android variants of the SDKs.
The native iOS and Android packages are being pulled in via External Dependency Manager for You (see this post, Play Services Resolver is the old name). When it runs, it looks for a file matching the pattern *Dependencies.xml and starts looking for native libraries to pull in.
Firebase includes a local Android maven repository at Assets/Firebase/m2repository which contains firebase-app-unity-6.14.0.srcaar with the Android C++ implementation. If you're not using gradle to resolve dependencies, it should copy the necessary components into Assets/Plugins/Android on build depending on your settings in the resolver:
Note that if you're using gradle, this package will be added to your mainTemplate.gradle. If there's no mention of it, something may have gone wrong.
--Patrick

Upgrading MariaDB 10.1.32 version to 10.3.7

Is it possible to upgrade from 10.1.x to 10.3.x directly in one step? or I have to upgrade first to 10.2. x then to 10.3.x.
Please it is so important question regarding upgrading our production MariaDB servers and I couldn't find any answer or notes regarding upgrade from 10.1 series to 10.3 series.
So i have to do it as follow:
10.1.32 --> 10.2.16
10.2.16 --> 10.3.7
or
once 10.1.32 --> 10.3.7
In general, for any upgrade for a critical production environment:
The best approach is to use or create a test environment that is as close as possible to your production environment and test the upgrade there.
Make backups and prepare a rollback so you are ready to undo your changes
For MariaDB specifically: to quote from other related questions on their support pages:
The main concern with skipping versions is that, while upgrading one major version is usually well-tested, skipping versions is not, so you
may bump into an incompatibility
Even if you find anecdotal indications that it worked for others, a database engine like MariaDB has possible complexities with different storage engines and the like that might make it more tricky in certain setups than in others.
1 : Shutdown or Quit your XAMPP server from Xampp control panel.
2 : Download the ZIP version of MariaDB
3 : Rename the xampp/mysql folder to mysql_old.
4 : Unzip or Extract the contents of the MariaDB ZIP file into your XAMPP
folder.
5 : Rename the MariaDB folder, called something like mariadb-5.5.37-win32, to
mysql.
6 : Rename xampp/mysql/data to data_old.
7 : Copy the xampp/mysql_old/data folder to xampp/mysql/.
8 : Copy the xampp/mysql_old/backup folder to xampp/mysql/.
9 : Copy the xampp/mysql_old/scripts folder to xampp/mysql/.
10: Copy mysql_uninstallservice.bat and mysql_installservice.bat from
xampp/mysql_old/ into xampp/mysql/.
11 : Copy xampp/mysql_old/bin/my.ini into xampp/mysql/bin.
12 : Edit xampp/mysql/bin/my.ini using a text editor like Notepad. Find skip-federated and add a # in front (to the left) of it to comment out the line if it exists. Save and exit the editor.
13 : Start-up XAMPP.
Note If you can't get mysql to start from Xampp control panel.
Add this 'skip-grant-tables' statement anywhere in xampp/mysql/bin/my.ini
file
14 : Run xampp/mysql/bin/mysql_upgrade.exe.
15 : Shutdown and restart MariaDB (MySQL).
If still mysql is not started then follow below Note steps(!Important)
Note :mysql error log file: c:\xampp\mysql\bin\mysqld.exe: unknown variable 'innodb_additional_mem_pool_size=2M' like please remove or commented this statement in my.ini file in this path xampp/mysql/bin/my.ini file.
Help from this link.

Resources