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:
you could easily modify the template linked in this tutorial to do a mysql backup instead https://blog.railway.app/p/automated-postgresql-backups...
Jump to solution
84 Replies
Percy
Percy2y ago
Project ID: f4ffaf00-bf8e-4fc7-8e95-9d64d9995b8d
Solution
Brody
Brody2y ago
you could easily modify the template linked in this tutorial to do a mysql backup instead https://blog.railway.app/p/automated-postgresql-backups
danielthames
danielthamesOP2y ago
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?
danielthames
danielthamesOP2y ago
this is my repo... independent mysql db I plan to create the project and then add it to this project
Brody
Brody2y ago
no what you are referring to would just be the postgres client library and the dump utility
danielthames
danielthamesOP2y ago
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
danielthames
danielthamesOP2y ago
Do you see something wrong? Should it work with the database shown above?
Brody
Brody2y ago
looks like it could work to me, but it's not like I've ever done this type of thing before
danielthames
danielthamesOP2y ago
ok what I'm going to have is something like this
danielthames
danielthamesOP2y ago
I will push the project and see what happens
danielthames
danielthamesOP2y ago
I'm going to use a test project just in case
Brody
Brody2y ago
sounds good
danielthames
danielthamesOP2y ago
It doesn't work
danielthames
danielthamesOP2y ago
basically the mysql db doesn't exists for my cron job
Brody
Brody2y ago
are you installing mysqldump into the container?
danielthames
danielthamesOP2y ago
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 ?
Brody
Brody2y ago
railway uses docker, so you can just install mysqldump the same way that the postgres backup cron job app installs pg_dump
danielthames
danielthamesOP2y ago
there's not a pg_dump; but I got you I'm going to run -> npm i mysqldump
Brody
Brody2y ago
pg_dump is installed with postgresql-client in the templates dockerfile
danielthames
danielthamesOP2y ago
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
Brody
Brody2y ago
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
danielthames
danielthamesOP2y ago
ok, I'm going to create this exact same file in my cronApp; changing pg_dump to mysqldump
danielthames
danielthamesOP2y ago
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.
Brody
Brody2y ago
mysqldump doesn't appear to be an alpine package
danielthames
danielthamesOP2y ago
yup!
danielthames
danielthamesOP2y ago
I'm almost there
danielthames
danielthamesOP2y ago
29c518cd-5f54-47a7-841e-9a5f4c8b2c3d project test ID
danielthames
danielthamesOP2y ago
final docker file just change the postgre client to mysql-client
Brody
Brody2y ago
are you checking if these are actually available alpine packages?
danielthames
danielthamesOP2y ago
it's trying to make the bkp; I'm getting an error now
danielthames
danielthamesOP2y ago
Brody
Brody2y ago
let's not resort to chat gpt lol
danielthames
danielthamesOP2y ago
lol
Brody
Brody2y ago
add mysql in line 22
danielthames
danielthamesOP2y ago
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 cryingman I'll delete this message...
Brody
Brody2y ago
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
danielthames
danielthamesOP2y ago
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
Brody
Brody2y ago
in the mean time remove mysqldump from your package.json
danielthames
danielthamesOP2y ago
Done! I've also moved the dev dependencies to their correct place
Brody
Brody2y ago
delete your Dockerfile and give this railway.json file a try
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"phases": {
"setup": {
"nixPkgs": ["...", "mysql80"]
}
}
}
},
"deploy": {
"numReplicas": 1,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"nixpacksPlan": {
"phases": {
"setup": {
"nixPkgs": ["...", "mysql80"]
}
}
}
},
"deploy": {
"numReplicas": 1,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
danielthames
danielthamesOP2y ago
weird error
Brody
Brody2y ago
one moment change your start script to node dist/index.js
Brody
Brody2y ago
the postgre backup template used node 18, try using node 18 set engines.node = 18 in your package.json
danielthames
danielthamesOP2y ago
I think I'm almost there
Brody
Brody2y ago
lol what solved those es5 errors
danielthames
danielthamesOP2y ago
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
Brody
Brody2y ago
removed the module type, makes sense since node 16 probably doesnt support the module type
danielthames
danielthamesOP2y ago
Brody
Brody2y ago
well is the file in cloudinary valid?
danielthames
danielthamesOP2y ago
danielthames
danielthamesOP2y ago
I'm gonna give it a try in my local db
Brody
Brody2y ago
yeah was just about to say to do a test restore
danielthames
danielthamesOP2y ago
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.
danielthames
danielthamesOP2y ago
by the way, this was an empty db only for test purpose .
Brody
Brody2y ago
sounds plausible, ive never used mysqldump
danielthames
danielthamesOP2y ago
lol the first instrucctions says -> --no-create-db --no-create-info --skip-comments mildpanic
danielthames
danielthamesOP2y ago
after
Brody
Brody2y ago
yeah that sounds like stuff you'd want
danielthames
danielthamesOP2y ago
awesome awesome awesome!!
Brody
Brody2y ago
you should totally make this into a template, if that's something you'd want to do
danielthames
danielthamesOP2y ago
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
Brody
Brody2y ago
awesome
danielthames
danielthamesOP2y ago
thank you very much Brody! have a good rest
Brody
Brody2y ago
haha no problem, happy to help!
danielthames
danielthamesOP2y ago
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.
Brody
Brody2y ago
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
danielthames
danielthamesOP2y ago
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 ...
danielthames
danielthamesOP2y ago
Should I have to add the variables I use?
Brody
Brody2y ago
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
danielthames
danielthamesOP2y ago
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.
Brody
Brody2y ago
Brody
Brody2y ago
now you just have to write info text for it and publish it
danielthames
danielthamesOP2y ago
where? how?
Brody
Brody2y ago
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
danielthames
danielthamesOP2y ago
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.
danielthames
danielthamesOP2y ago
Brody
Brody2y ago
sounds good
danielthames
danielthamesOP2y ago
Ok done! thanks for the patience Brody
Brody
Brody2y ago
no problem, im happy i could help!
Want results from more Discord servers?
Add your server