Ad Widget

Collapse

Shedule backup for Zabbix DB by cronJob

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prasad_SL
    Member
    • May 2018
    • 35

    #1

    Shedule backup for Zabbix DB by cronJob

    Hi,
    I want to daily backup my Zabbix DB and archive weekly backups compressed to a different folder.

    I tried by modifying crontab file at /etc.
    For testing I want to trigger dump every 5 Minutes to location /home/appliance/iCAMbackup/day/
    with day time stamps in the backup file.
    $(date +'%Y%m%dAT%H%M%S')ratZdbbackup.sql

    shell command tested ok;
    mysqldump -uzabbix -phWaLjNb919 zabbix > /home/appliance/iCAMbackup/day/$(date +'%Y%m%dAT%H%M%S')ratZdbbackup.sql

    But no output with cron.
    even after restarting the zabbix.

    Any help ???


    # /etc/crontab: system-wide crontab
    # Unlike any other crontab you don't have to run the `crontab'
    # command to install the new version when you edit this file
    # and files in /etc/cron.d. These files also have username fields,
    # that none of the other crontabs do.

    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

    # m h dom mon dow user command
    17 * * * * root cd / && run-parts --report /etc/cron.hourly
    25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
    5 * * * * mysqldump -uzabbix -phWaLjNb919 zabbix > /home/appliance/iCAMbackup/day/$(date +'%Y%m%dAT%H%M%S')ratZdbbackup.sql
    #

  • zux
    Member
    • Sep 2018
    • 93

    #2
    I think this crontab configuration will ran at :05 every hour, not every 5 minutes

    Comment

    • prasad_SL
      Member
      • May 2018
      • 35

      #3
      Thanks Z,




      You are correct.

      It shall be ,

      # m h dom mon dow user command
      17 * * * * root cd / && run-parts --report /etc/cron.hourly
      25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
      47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
      52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
      */5 * * * * appliance mysqldump -uzabbix -phWaLjNb919 zabbix > /home/appliance/iCAMbackup/day/$(date +'%Y%m%dAT%H%M%S')ratZdbbackup.sql
      #

      And I forget to restart the corn ...

      sudo /etc/init.d/cron restart

      Thanks bro...

      I will write the script for the Archive mechanism and share tomorrow..

      Comment

      • youngy
        Junior Member
        • Oct 2018
        • 7

        #4
        This is what we do for postgres under cron for the postgres user


        00 22 * * Sat cd /mnt/<somewhere>/databases && pg_dump zabbix | gzip > zabbix.pg_dump.sql.`hostname -s`.`date +"\%Y_\%m_\%d"`.gz

        runs every Saturday at 22:00

        probably only partially helpful.

        Comment

        • prasad_SL
          Member
          • May 2018
          • 35

          #5
          Thanks Y,

          Comment

          • prasad_SL
            Member
            • May 2018
            • 35

            #6
            Hi,

            Following are the codes.

            Backup location : /home/appliance/iCAMbackup/day


            Script file : Mark4.bash

            #!/bin/bash

            ratT="$(date +'%Y%m%d.%H%M%S')"
            echo "Autobackup start at $ratT" >> /home/appliance/iCAMbackup/backuplog.txt

            fileName="$(date +'%Y%m%dAT%H%M%S')ratZdbbackup.gz"
            mysqldump -uzabbix -phWaLjNb919 zabbix | gzip -c> /home/appliance/iCAMbackup/day/$fileName

            ratT="$(date +'%Y%m%d.%H%M%S')"
            echo "Autobackup file $fileName complite at $ratT" >> /home/appliance/iCAMbackup/backuplog.txt

            exit


            crontab entry:

            0 0 * * * appliance /home/appliance/iCAMbackup/Mark4.bash


            Restart corn

            (on Ubuntu)

            sudo /etc/init.d/corn restart

            We are done....


            Now backup file generated every mid night, compressed.


            Backup log file output:

            Autobackup start at 20181023.000001
            Autobackup file 20181023AT000001ratZdbbackup.gz complited at 20181023.000123

            Now we have to manage backup files.. since every day we get new backup file.
            So I hope to write script to archive old backups, (more than 10 days old) to a different folder.

            I will upload codes, ones it done.
            If any one have better way; please share ...



            Comment

            • kloczek
              Senior Member
              • Jun 2006
              • 1771

              #7
              crotab entries like above does not make to much sense.
              1) backup is not made with locking database co what lands in backup is not consistent
              2) locking DB and making text dump in case enough big databases may take hours if not days
              3) only solution for enough big databases is warm backup which consist out of:
              - locking database for writes
              - flushing all not written data to the storage
              - make block layer of VFS layer snapshot
              - unlock database
              - preserve content of the database by copy/backup snapshot content

              Usually to be able use such backup to (re_create slave database it is necessary to create file with current DB transaction number before make snapshot (to have such file with this information part of the snapshot).
              In other word: text backup has very limited usability because it is to slow. Import of the text dump may take in case of some DB engines even longer than dump.

              Answer on you question about kind of backup module is: no, there is no such thing because exact backup technique depends on DB engine, properties of the storage and.or FS used by DB engine and other factors.
              In other words universal "backup module" could be as much complicated as zabbix themselves,
              http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
              https://kloczek.wordpress.com/
              zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
              My zabbix templates https://github.com/kloczek/zabbix-templates

              Comment

              • prasad_SL
                Member
                • May 2018
                • 35

                #8
                Dear Rohit,

                Got your idea,
                Thanks.

                There is no inbuilt tool. (As per my knowledge)

                The purpose of the backup (in my case) to restore zabbix to its latest snap, in case of a total failure.
                I have a VM image, and I tested restoring DB ; works fine for me.
                1.I have initial Zabbix VM (Customized with my scripts)
                2.I have latest DB

                You are correct !

                My method consume lot of HD space and time consume for dump (As K describes above)
                The better way to do this may be,

                1.Keep full DB backup monthly basis
                2.Produce incremental Backups (As your post) daily, weekly....

                Also, we can do custom script to specify backing up selected tables only
                zabbix has number of tables.
                We can select the tables according to the context of our requirement.

                I will re post scripts ones I complete.

                Thanks R, Thanks K ...

                Comment

                • kloczek
                  Senior Member
                  • Jun 2006
                  • 1771

                  #9
                  Originally posted by prasad_SL
                  1.Keep full DB backup monthly basis
                  2.Produce incremental Backups (As your post) daily, weekly....
                  Incremental backups can be done over collecting and preserving DB engine binary logs.
                  In case of using zfs as storage binary data generated by "zfs send" command between snapshots(similar with btrfs)
                  http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
                  https://kloczek.wordpress.com/
                  zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
                  My zabbix templates https://github.com/kloczek/zabbix-templates

                  Comment

                  • Mike2K
                    Member
                    • Oct 2018
                    • 62

                    #10
                    Just a quick question...
                    Why are you trying to do this rather complicated job (like kloczek explained very thorough) yourself instead of using a backup agent like Veeam (free) and others ?

                    Comment

                    • prasad_SL
                      Member
                      • May 2018
                      • 35

                      #11
                      Thanks M,

                      I will try that tool..


                      Same time... coding is fun ..

                      Comment

                      • prasad_SL
                        Member
                        • May 2018
                        • 35

                        #12
                        Dear M,

                        The proposed tools not serving my propose.
                        Also, I have VM image monthly backups already..

                        "Why are you trying to do this rather complicated job" ??

                        My requirement is rather simple.
                        I want to backup my zabbix configuration data, in an event of total system failure.

                        So its not much complicated as capturing 100% instant snap data.
                        Also, selected tables with incremental backup was rather fast ...

                        In that way I only need very small disc space to manage my configurations.


                        Dear All,

                        If anyone interested, I will post all folder structure and 3 script files with cron configurations.
                        Its just a 10 minutes work, ones you have those.


                        I am new to Zabbix and Linux, so may be this is not the best way to do it.
                        But it was fun.

                        Comment

                        Working...