2

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.

5
  • Remotely mount the directory with the DB via the remote files system of your choice, preferably r/o. Commented Jul 23, 2015 at 9:17
  • Thanks, but am looking for other ways to get this done. Commented 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 ... Commented Jul 23, 2015 at 9:31
  • Could you please explain a bit more? Yes I want to select and update data in db tables. Commented 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. Commented Jul 23, 2015 at 9:57

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Ohk, but are there other ways? Any trick that I can do using Django?
As I said, this happens at the filesystem level, so no python or django tricks. I would strongly recommend you to switch to a proper db since you are into such issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.