Those of us who manage servers know how important it is to have saves, backups of everything ... well, in case of any problem or failure, the backup will be our best friend and will help us restore services 🙂
Some time ago (several months ... quite a few months) here, configurations were not backed up on servers, logs or something like that automatically. And it just couldn't be like that haha, I considered using bacula, but God!! For what I wanted this was too, very, very complicated in my opinion, if what you want is to simply make backups and save these (or send them to another server, or by email) there is no need to use Bacula, with a simple script all problems are solved, hence I decided to make my own script and thus I was more satisfied 😀
And precisely this script is the one that I share with you, I explain very briefly what it does:
- Create a folder where everything will be saved, and this folder is the one that will then be compressed.
- This folder will have the name of the year, month and present day, for example today that folder would be called: 2012-04-26
- Copy / etc / (and all its content) to that folder.
- Copy logs (/ var / log /) to that aforementioned folder.
- Export the MySQL databases that we have.
- Compress with a password (PASSWORD) that folder, compress it into RAR.
- Generate a file (data.info) with all the log of the above done (file copy log and compression to .rar), in addition to putting the size (in MBs) of the .RAR file, which I remind you, contains everything we decided to save.
- Delete the folder in which we put the files and then compressed, because if we already have this compressed folder, there is no need to also have it uncompressed.
- Send emails to administrators or people related to the server, informing that the backup was done correctly, and the file with the log of everything will be sent attached to that email (data.info.rar)
Obviously, this script is not to be executed and now haha, you must open it and change your MySQL password in it, because I do not know the root password of your databases LOL !!!, as well as change the emails to the They want the notification to be sent, because the emails I put are only for example.
If you want to compress it into .tar.gz and not in .rar (how the script is configured) there I left the commented line, it is just uncomment it and comment on the .rar. Likewise, if you want to copy by SSH (using SCP) the compressed file to another server or hosting, I also left the line at the end (it is commented), in it you must put the access data to your server or hosting (user and domain or server URL), but for this to work you must also configure SSH without password, since the script will not be able to access the server if it does not have access allowed on it.
Ah, if you want the email sending thing to work, you must have postfix installed on the server, almost all install postfix but hey, the clarification is valid 🙂
Although ... they could modify and use a script in Python that I left a while ago, but I think it would work a little more ^ - ^ U
And well, it only remains to leave the script:
VPS Backup Script
Remember that you have to give it execution permissions (chmod + x vps_backup-script.sh)
To get it to run every day at 10AM, they put this in a terminal:
echo "* 10 * * * root cd /root && ./vps_backup-script.sh" >> /etc/crontab && /etc/init.d/cron restart
Assuming the script is saved as: /root/vps_backup-script.sh
Well enough, I don't want to make this seem too complicated, which is not haha, actually this is something extremely simple, only that when you see it for the first time it can be a bit scary 🙂
Let me know any doubt, question or suggestion, you know that I like to help 😀
regards
PD: I clarify that I am not nor do I consider myself a programmer haha, not even close LOL !! I know the script can be optimized much more, but hey… I'm not a programmer
Putting away,
Regards,
How are you very interesting, but one caveat; if that script is run today it will be called 2012-04-25, today is the day of the watch.
Thank you
faustod
HAHAHA true hahaha, is that I like I live in the future ... LOL !!!
Very interesting, in fact it shows me how to do various things, I am developing my own and I am going to take some pieces of code from yours to add functionalities.
In my case I will use rsync instead of cp to copy the files.
Regards !!
Yes, using rsync is a good idea but I preferred to use cp because, I will copy files to a blank folder, I will not sync with any other information haha that's why I just used cp :)
If you want to know more tips for bash check the tag here on the site ... you will find how to make lock files, control which users can execute the script, etc 😀
https://blog.desdelinux.net/tag/bash/
Greetings and thanks for commenting 🙂
a server with ssh without password?
Not without a password, but accept SSH connections with confidence from a specific IP, this is done in a VERY secure way with the use of public and private keys, in the link that I left I explain everything in detail 🙂
With keys yes, for a moment I was scared xD
LOL!!! nor that I was suicidal LOL !!!
No, but inside things we are, you really like to complain
great this script.
hope they keep posting scripts. help those of us who are switching to linux to be more productive in time and in reducing learning time.
😀 thanks to you for commenting.
Soon I will publish another tip about bash 😉
regards
thank you crazy! one day I will return the favors that the comrades of this beautiful linux community give me!
How can I copy the content of several log files and place it in a single file ,,,, automatically every 5 minutes, taking into account ,,,,, that the content of the files to be copied is constantly measured
My recommendation, (suggestion), would be a contribution… Create a condition that every 5 minutes he verifies the file or files, either with:
* last access = atime
* last modified = mtime
* last information change = ctime
Accordingly, if there is any change in the files, group them and / or read them (cat) and send them> logs files.
This is a clear example, a matter of testing, trying, verifying and modifying.
Testing Caché Plugin ...
Very good information, the truth that was very useful to me, I am carrying out a large project (obviously it is fictitious, because it is from the studio) and this information was very useful for me.
Thank you so much!!
How would you make a shell script that :?
Ask the user to specify the name of the directory to backup
Ask you for the location where you will backup the directory
Include backup date
Hello,
With "read" I can ask the user for all that data, then I assign it to variables and that's it.
Write to my email if you have questions: kzkggaara[at]desdelinux[dot]net
regards
PS: The backup date is already included in the script.
present a simpler script to backup folders from ubuntu and transfer them by ftp to another server thanks
Hello, how do I make a backup of the entire linux operating system and send it to another pc. I would appreciate your attention, thank you very much !!
Could you send me the script to my email fvaldettaro@gmail.com please.
Could you please send me the script to my email, thanks a million, greetings.
Good morning friend, I think you have a problem with the "paste" subdomain because I was checking some published codes/scripts that lead to paste.desdelinux and they all redirect me to blog.desdelinux.
Yes, it is not possible to access the script because paste. redirects you, can you upload it somewhere else?
Has the problem to get the script been solved?
Thank you.
It has been fixed, they can now access the codes
Now, thank you!
good afternoon, I would like to be able to download the script, it would be possible to upload it again, now it is not available
Hello,
Very good contribution! Could I ask you for the script to download? Thank you very much 🙂