Bash script to make a backup of your important things

My parents and acquaintances often joke that I am a 'mole' with technology, that I have broken more devices or PC components than anyone else. The funny thing is that they are not wrong 😀

I have not done it on purpose, but in my possession about 5 or 6 HDDs have broken, so data loss for me is a serious problem LOL !!

So, to avoid losing really important data, sensitive information for me the most basic thing would be to copy these data, these important folders to another place, right? But it happens that what I wanted to save was not one or two folders, but several more ... and as if that were not enough I am too lazy to navigate through my Personal Folder and others selecting folders to copy them to another place hahahaha, instead of this , to save time and effort, I made a small and simple script that allows me to execute save everything I want 😀

What specifically does this script do?

  1. It enters a folder where I will work or base folder.
  2. Inside it create a new folder, the name of this will be the current date (for example: 2012-07-08).
  3. Copy Firefox, Chromium, Opera, KMail settings (+ contacts and our emails), Rainlendar2, Pidgin, Kopete, Konversation, KWallet ... that is, it copies a series of files and / or folders that we need to save. What to save is completely modifiable, we can change this at will.
  4. Export any database that we have, in my case I put two databases to save (dbtest y bNC). For this the MySQL server must be started.
  5. Then delete our Firefox and Opera cache that we copied, since we do not want to save the cache.
  6. Finally compress in .RAR and with a password that we want all this.
  7. Also if we want, instead of compressing in .RAR we can compress everything in .TAR.GZ, I left the commented line in case you want to use this.

Personal backup script

They must download it, give it execution permissions and that's it.

Ah, in your personal folder you must have a folder called WORKING (all in capital letters), because that's how I use it.

Do not worry, I explained the script step by step with comments, if someone wants to make any kind of change, if you want to modify something to satisfy any need ... just tell me, I will gladly make the arrangements you want 🙂

Greetings and I hope you find it useful.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   msx said

    It's good, but I would use - and abuse - Rsync and 7zip instead of RAR.

    In fact yesterday I backed up the / (with fsarchiver), ~ / .kde4 and the boot sector (I use GRUB Legacy so with dd if = / dev / sda of = MBR bs = 1 count = 512 it reaches me) and I put everything on a DVD that is already archived.

    Now that I have the machine working as I want with the system tuned to the maximum and KDE that is flawless with Ulatencyd and all the other tweaks for the hybrid video cards, mother, HD, cpu, swap, etc., if I send mucus and break this installation I abandon Arch until 2025 at least, I don't think I have the mental fortitude to do everything I did to the system again to leave it running like this O_o

    Of course, I already have an uptime of 12:24 hours in a row - I'm taking root in this chair - and the notebook is frozen, proof that the opensource RadeonHD driver can be used perfectly without using the proprietary Catalyst - as long as we don't need the 3D acceleration provided by the latter.

    Salu2

    1.    KZKG ^ Gaara said

      I chose to simply use cp instead of rsync because it is a simple copy what I want to do, also if someone wants to modify the script ... I imagine it will be simpler if they put it with cp instead of rsync 😀

      1.    Hugo said

        I usually use directly tar -rzvf for quick saves. If what I want is that it compresses well, I use 7za to -mx = 9 -ms = on. With Rsync you have to be careful, because if it is used badly you can destroy information.

  2.   marcpv89 said

    When I read the name of the article I knew it was you, and you have very good reason, since you have a PhD in breaking components of your PC (remember your mike). It suits me very well, especially with the virus that I have at home that begins with h and ends with a. (sister)

    1.    KZKG ^ Gaara said

      HAHAHAHA yes… but eehh !! the mike kept working 😀
      I also have keyboards and mice in my history LOL!

      Come on, if your sister is a little angel ... that girl is the best, what you treat her badly.

  3.   Rayonant said

    Very useful indeed, I will modify it for my needs because from time to time I also make my backups of important data, it is also perfectly commented so the possibilities are immense, for example in my case I have an external disk for this purpose so $ HOME / WORKING will go to se / media / external_disk. Thank you so much!

  4.   crotus said

    Very good KZKG ^ Gaara! Thanks for detailing all the features. It's been a little while since I started with Linux (Debian) and I see that scripts are essential to automate tasks, now I'm going to build one to install debian from scratch but I have to learn several things, especially the GREP command to modify .conf.
    One question: What backup / synchronization methods do you use? I have seen that some use cpio, rsync… someone uses Wuala to synchronize the HOME folder?
    Regards!

    1.    KZKG ^ Gaara said

      Hello, how are you?
      Well, if you are looking for bash ... scripts, come over here, we have put a lot of scripts and things: https://blog.desdelinux.net/tag/bash/

      I use cp in my scripts, because using cp and also programming functions and cycles, I get everything to work much more than well 😀
      However, rsync is really great, it does much more than just make backups 😉

      It is up to each user to know when to use one or when to use another.
      regards

      PS: Nothing man, a pleasure to help ... describing each step does not bother me if this way I will help others.

      1.    crotus said

        I have to entertain myself! I will also review the "PASTE" to learn.

        1.    KZKG ^ Gaara said

          Uff there are a lot yes hahaha.

  5.   auroszx said

    Very good, although I make entire backups of the disk with dd xD

    1.    Hugo said

      Man, for that better use clonezilla, hehehe.

  6.   Aleph said

    For databases, I recommend mysqlhotcopy, because with mysqldump in a large database, it takes time to backup and during that time changes are made, what you are going to get is a corrupt backup that will not work for you. mysqlhotcopy, applies a lock table before the backup, which guarantees that what you save will work.

    1.    KZKG ^ Gaara said

      Interesting yes.
      In this example the backup is personal, that is, everything on localhost… so the DB should not undergo changes while the dump is being done. However, in hosting or server backups, it can happen.

      Interesting tip yes 😀
      Thanks.

    2.    Hugo said

      Interesting, thanks for the tip. Until now I hadn't needed to save databases because I didn't have anything critical, but apparently I'm going to need it soon.

  7.   elynx said

    Luxury man, if you are a valuable man !.

    Greetings and Thank you very much for such a great Utility!

    PS: Some tutorials to learn to program in bash in linux? .. I also have a question, with crontab we cannot do this type of task in X time ?, that is, program a script that makes backups every X time that we have assigned?

    1.    KZKG ^ Gaara said

      Thank you Hahahaha.
      About the tutorials, mmm we have put several articles on bash, and 2 or 3 are for newbies or beginners: https://blog.desdelinux.net/tag/bash/

      And yes, if in the crontab we put an order / task to be executed at X hour it will do it, only that this script is vaaarrriiiasss tasks to be executed, putting all this in the crontab is outrageous hehe.
      What you do is create a script (like this), and then in the crontab we configure it to execute the script 😉

  8.   Xose M said

    thank you so much,
    in my case it is precisely to automate the copies of the databases where it will be useful 😉

    more info about cron in https://help.ubuntu.com/community/CronHowto . You can use the hourly, monthly, ...

  9.   Nonamed said

    grsync r00lz, thanks to him I can be calm

  10.   vicen said

    I can't access the script links, can you put it back? THANKS

    1.    KZKG ^ Gaara said

      My apologies, it was an error on our server that made the link inaccessible, here you have it working fine again 😀 - » http://paste.desdelinux.net/4482

  11.   Rodrigo Prieto said

    Thanks for the script! as always very useful !!

  12.   Paco said

    could you go back up or pass me the script ??
    can no longer be downloaded