I have a Django application that runs on apache server and uses Sqlite3 db. I want to access this database remotely using a python script that first ssh to the machine and then access the database.
After a lot of search I understand that we cannot access sqlite db remotely. I don't want to download the db folder using ftp and perform the function, instead I want to access it remotely.
What could be the other possible ways to do this? I don't want to change the database, but am looking for alternate ways to achieve the connection.
-
Remotely mount the directory with the DB via the remote files system of your choice, preferably r/o.Klaus D.– Klaus D.2015年07月23日 09:17:08 +00:00Commented Jul 23, 2015 at 9:17
-
Thanks, but am looking for other ways to get this done.user3891554– user38915542015年07月23日 09:29:47 +00:00Commented Jul 23, 2015 at 9:29
-
1@user3891554 you mean you wanted to access db tables and row and all ah ? then best way is to use REST and made web interface ...Raja Simon– Raja Simon2015年07月23日 09:31:36 +00:00Commented Jul 23, 2015 at 9:31
-
Could you please explain a bit more? Yes I want to select and update data in db tables.user3891554– user38915542015年07月23日 09:34:47 +00:00Commented Jul 23, 2015 at 9:34
-
if the actions you want to make on the database are very specialized, you could launch a local script with some arguments to tell it what to do, I guess, but it would be really complicated as you'd also have to parse the result in the script that lauched the ssh connection. Mounting the filesystem, on the other hand, woud be way easier and wouldn't force you to have such a complicated and limited process.BriceP– BriceP2015年07月23日 09:57:23 +00:00Commented Jul 23, 2015 at 9:57
2 Answers 2
Leaving aside the question of whether it is sensible to run a production Django installation against sqlite (it really isn't), you seem to have forgotten that, well, you are actually running Django. That means that Django can be the main interface to your data; and therefore you should write code in Django that enables this.
Luckily, there exists the Django REST Framework that allows you to simply expose your data via HTTP interfaces like GET and POST. That would be a much better solution than accessing it via ssh.
Comments
Sqlite needs to access the provided file. So this is more of a filesystem question rather than a python one. You have to find a way for sqlite and python to access the remote directory, be it sftp, sshfs, ftp or whatever. It entirely depends on your remote and local OS. Preferably mount the remote subdirectory on your local filesystem.
You would not need to make a copy of it although if the file is large you might want to consider that option too.