How to download updated sqlite Database from AWS EB? (Django app) - django

I have deployed my django app on AWS Elastic beanstalk, using the sqlite database. The site has been running for a while.
Now I have made some changes to the website and want to deploy again, but by keeping the changes the database went through(by form inputs)
But I am not able to find a way to download the updated database or any files. The only version of the app I am able to download is the one I already uploaded when I first deployed.
How can I download the current running app version and deploy with the same database?

you may use scp to connect to remote server and download all your files.
as commented, you should better use dumpdata and then i/o that file (instead of the db or full site).
however, if your remote system python version is not the same as your django site, then the dumpdata may not work (this is my case), so I managed to download the whole site folder back to local and then use dumpdata
aws elastic beanstalk Python app's files in /opt/python/current/app
just use scp -r to download the whole site to local.

I believe you have sqlite db file being packaged from your local during eb deploy. If that is a case then all you need to do is not include db.sqlite file in your deployments.
Move location of db.sqllite file to s3 or ebs persistent volume so that it persists.
Use .ebextentions to run db migration in aws on top of the aws db file just the way django recommends.
To be on safe side you can ssh into your eb env which is ec2 instance and download db.sqlite file just incase.

Related

Moodle on Heroku using S3 Bucket

I'm trying to set up Moodle on a free Dyno on Heroku.
I started my project with the stable version 3.10 of Moodle on a new repository.
I've created the Heroku app and connected my github repository to it
I've created an S3 Bucket that allows read and write access to objects from anyone
On config.php:
I changed the database settings (to point to the free postgres database that I also created),
I've set wwwroot as my Heroku app (http://myherokuappexample.herokuapp.com/)
I've set dataroot as my S3 Bucket endpoint (https://mys3bucketnamexample.s3.eu-north-1.amazonaws.com/moodledata/)
I created the folder moodledata, added an image to it and I was able to access it from the browser (for example https://mys3bucketnamexample.s3.eu-north-1.amazonaws.com/moodledata/ola.png)
BUT I'm getting "Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting." when the app is deployed to Heroku.
What am I doing wrong?

How do I access beanstalk application venv?

this last week I have been trying to upload a flask app using AWS Beanstalk.
The main problem for me was loading a very heavy library as part of the bundle (there is a 500mb limit for uploading the bundle code).
Instead, I tried to use requirements.txt file so it would download the library directly to the server.
Unfortunately, every time I tried to include the library name in the requirements file, it failed to load it (torch library).
on pythonanywhere server there is a console which allows you to access the virtual environment and simply type
pip install torch
which was very useful and comfortable.
I am looking for something similar in AWS beanstalk, so that I could install the library directly instead of relying on the requirements.txt file.
I have been at it for a few days now and can't make any progress.
your help would be much appreciated.
another question,
is it possible to load the venv to Amazon-S3 and then access the folder from the beanstalk environment?
Its not a good practice to "manually" install your dependencies or configure your EB env from inside. This is only useful for testing and debugging purposes. Thus keep that it mind.
To get your venv, you have to ssh to your EB instance using regular ssh or web-based clients available in AWS EC2 console when you locate your EB EC2 instance. Session manager should work out-of-the-box to enable you to login to the instance.
When you login to the instance, then to activate your venv, you do:
# start bash
bash
# source venv
source /var/app/venv/staging-*/bin/activate

Deploying Flask App with sqlite db in AWS Elastic Beanstalk

I have the tutorial app from the flask docs and modified for my use.
I was able to deploy my flask app and create the db via container_commands (flask init-db)
But when I try to write something to the db from the web browser. It throws the exception that
"sqlite3.OperationalError: attempt to write a readonly database"
It seems the problem is the write permission to the sqlite file. But it was created at the time of deploying the application. Any help.
Ideally when you are deploying in your own production env (not cloud), the sqlite is created in the venv/var/app-instance folder. How do I access this in AWS EB.
It looks like file write permission issue to me as well.
here is how i would troubleshoot the issue:
login to the instance via ssh, give permission to the file and see if it resolves the issue.
if it does resolves the issue, I would automate that using .ebextensions
Hope this helps you move forward.
Also look at the reference below shows how to change file permissions.
Reference: python sqlite3 OperationalError: attempt to write a readonly database

Django Web application publishing

How to publish django web application? what are the steps to be followed for publishing a django application? is there any free hosting for pulishing?
thanks in advance
I am using PythonAnyWhere for hosting my project. They provide hosting for python-Django / flask specificly and have a very dedicated team.
You can host your app for free but you can not use your own domain. To use custom domain, you need to purchase paid plan starting from $5 per month.
Their customer support is extremly good.
Steps to follow for hosting:
- Make sure your code is production ready i.e. well tested and bug free.
- Separate production and dev settings file. On production you need to set DEBUG=false.
- Push your code to github. Do not commit sensitive information like credentials or api keys. Keep them in .env file.
- Create account on pythonanywhere server and create database.
- Clone the git repo. Complete the web setup step. Edit the wsgio settings file.
- Run migrations. python manage.py migrate.
- Create cache table if any python manage.py createcachetable.
- Collect static files python manage.py collectstatic.
- Reload the web app.
Refer this step by step article to setup a free account and host web app on pythonanywhere server.
I'm a big fan of Amazon Web Services if you want simplicity and automation. You can create a CodeStar project for Django and Elastic Beanstalk. Everything is set up from you, so as soon as you commit code to your github repo (it even can create the repo for you with the elastic beanstalk config files), it builds, tests, then deploys it.
The best part is you can utilize amazon's free-tier level if you are a new member so it's probably going to be free or extremely cheap.
Look here for reference:
https://aws.amazon.com/codestar/faqs/
digitalocean.com is good for hosting. link
I used this for Django 2.0 with python3.

Joomla Backup to run Locally

Can a downloaded backup of Joomla website be run on localhost? If yes, what changes I need to do locally?
I placed the unzipped backup folder under C:\xampp\htdocs\joomla. So now as I try to run loclhost //localhost/joomla it gives me following error.
Database Error: Unable to connect to the Database: Could not connect to MySQL.
Please note that I've not done any changes to backup. Just placed the unzipped backup downloaded via FTP in htdocs.
You will also need to download a copy of the website database and install this locally. If this is new to you, check out Akeeba Backup, it will simpplify your life when moving sites between different servers. It will bundle the database and site files into a nice, neat zipped package for you.
Chances are the database specifics are incorrect. Unless you have created the exact database name and user on localhost you'll need to edit configuration.php to straighten that out.