How can I create daily backups of my Mysql database?
Hi everyone!
I want to create daily backups of my Mysql database, I'm not sure if I should create an app with a cronjob or something like that.
Can anyone help me with this? There's no option in the project settings.
Thanks.
ProjectID
f4ffaf00-bf8e-4fc7-8e95-9d64d9995b8d
Solution:Jump to solution
you could easily modify the template linked in this tutorial to do a mysql backup instead
https://blog.railway.app/p/automated-postgresql-backups...
84 Replies
Project ID:
f4ffaf00-bf8e-4fc7-8e95-9d64d9995b8d
Solution
you could easily modify the template linked in this tutorial to do a mysql backup instead
https://blog.railway.app/p/automated-postgresql-backups
Hey I want to work on this now! @Brody
I saw that the example contains a dockerfile with the postgree config inside
is that correct? the postgree db runs inside the docker? Do I need a docker file?
this is my repo... independent mysql db
I plan to create the project and then add it to this project
no what you are referring to would just be the postgres client library and the dump utility
I have my node cron app ready
to get the mysql db and then upload it to cloudinary - this is based in the example with postgree
here you can see the screenshot to dump the file
Do you see something wrong? Should it work with the database shown above?
looks like it could work to me, but it's not like I've ever done this type of thing before
ok what I'm going to have is something like this
I will push the project and see what happens
I'm going to use a test project just in case
sounds good
It doesn't work
basically the mysql db doesn't exists for my cron job
are you installing mysqldump into the container?
it's not a container
Should I work with docker? I need to migrate my db from standalone railway mysql to a docker container with mysql + cronApp ?
railway uses docker, so you can just install mysqldump the same way that the postgres backup cron job app installs pg_dump
there's not a pg_dump; but I got you
I'm going to run -> npm i mysqldump
pg_dump is installed with postgresql-client in the templates dockerfile
ok I see that it doesn't work only installing it; but I see what I can do with this package
I will make some modifications and try it
you don't need to change your code lol
just install mysqldump in the container
whether you do that with a dockerfile or a railway.json file is up to you
ok, I'm going to create this exact same file in my cronApp; changing pg_dump to mysqldump
https://github.com/danielthames360/cronJob
by the way, this is my repo
GitHub
GitHub - danielthames360/cronJob
Contribute to danielthames360/cronJob development by creating an account on GitHub.
mysqldump doesn't appear to be an alpine package
yup!
I'm almost there
29c518cd-5f54-47a7-841e-9a5f4c8b2c3d
project test ID
final docker file
just change the postgre client to mysql-client
are you checking if these are actually available alpine packages?
it's trying to make the bkp; I'm getting an error now
let's not resort to chat gpt lol
lol
add mysql in line 22
RUN apk add --update --no-cache mysql mysql-client nodejs npm
same error after deploy it
https://chrisshennan.com/blog/fixing-authentication-plugin-cachingsha2password-cannot-be-loaded-errors
I'm not sure
Hey man! we can continue tomorrow if you want; I don't want to waste your Friday time
I'll delete this message...
nah it's good my Friday night has already come to an end
and tbh I don't actually know why the original template uses a dockerfile, everything it does can easily be configured through a railway.json file and built with nixpacks
once I'm back on my computer in a bit I can try to slap together a railway.json file for you
I appreciate your time! and help
If you know anything I can do to make it work would be fantastic. I am not in any hurry.
So, I can wait pattienly
in the mean time remove
mysqldump
from your package.jsonDone! I've also moved the dev dependencies to their correct place
delete your Dockerfile and give this railway.json file a try
weird error
one moment
change your start script to
node dist/index.js
the postgre backup template used node 18, try using node 18
set engines.node = 18 in your package.json
I think I'm almost there
lol what solved those es5 errors
it was... Firstly, I was working with javascript only. Then, I migrated the project to typescript and I don't needed the type: module on package.json anymore
removed the module type, makes sense since node 16 probably doesnt support the module type
well is the file in cloudinary valid?
I'm gonna give it a try in my local db
yeah was just about to say to do a test restore
oh; these are the lines
maybe I need to add/update some lines of my mysqldump instruction in order to have a fully backup with schema creation, data and so on.
by the way, this was an empty db only for test purpose .
sounds plausible, ive never used mysqldump
lol the first instrucctions says -> --no-create-db --no-create-info --skip-comments
after
yeah that sounds like stuff you'd want
awesome awesome awesome!!
you should totally make this into a template, if that's something you'd want to do
I will update the code to work with a specific folder or some specific things of my liking (cloudinary stuff too).
Tomorrow morning I will test this project with the real production application, and make the cron work based on a configuration.
With that I think I'll be all set and the project will be fully configurable.
I'll attach some screenshots here
awesome
thank you very much Brody!
have a good rest
haha no problem, happy to help!
definitely! I'm not sure how to do that
but just let me know what I can do
tomorrow, I'll clean the code and do what I described above.
https://railway.app/account/templates
New Template
add your public repo, and configure all the variables and such, if you need any help with that tomorrow feel free to ask me
hey Brody!
I have the app ready to create the template
https://github.com/danielthames360/mysqlCloudinaryBackups
Would you suggest something?
GitHub
GitHub - danielthames360/mysqlCloudinaryBackups: Node.js applicatio...
Node.js application that performs scheduled backups of your MySQL database and uploads them to Cloudinary for secure storage. - GitHub - danielthames360/mysqlCloudinaryBackups: Node.js application ...
Should I have to add the variables I use?
just add all the variable names you have in your .env.example file, with no default value
like how this does it
https://railway.app/new/template/I4zGrH
Railway
Deploy mysqlCloudinaryBackups on Railway
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
now you just have to write info text for it and publish it
where? how?
ohhh publishing templates is a beta feature
so just type /beta here
so are you gonna upgrade to the dev plan too? otherwise you won't be able to run the backup 24/7
yeap! my client has their credit card in his account
we have the production project there
I don't need a plan for my personal account yet.
sounds good
Ok done!
thanks for the patience Brody
no problem, im happy i could help!