• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

Resetting FOG Snap In IDs

Scheduled Pinned Locked Moved
General Problems
4
11
2.9k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T
    THEMCV
    last edited by Jan 4, 2017, 3:51 PM

    I found the script that @Wayne-Workman posted for fixing the numbering of the image IDs (which worked great!)

    Is there a script or a way to reset the ID numbers of the snap ins? We’re getting into the 20s-30s and the numbering is becoming a bit sporadic during full registration.

    Thanks. 🙂

    1 Reply Last reply Reply Quote 0
    • T
      Tom Elliott
      last edited by Jan 4, 2017, 4:14 PM

      The principle used for the image id’s should also be able to be used for snapin id’s.

      Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

      Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

      Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

      T 1 Reply Last reply Jan 4, 2017, 5:10 PM Reply Quote 0
      • T
        THEMCV @Tom Elliott
        last edited by Jan 4, 2017, 5:10 PM

        @Tom-Elliott I’ll have to go through the script and see if I can figure it out by changing the variables in it. Guess I can’t break too much. 🙂

        T 1 Reply Last reply Jan 4, 2017, 5:11 PM Reply Quote 0
        • T
          Tom Elliott @THEMCV
          last edited by Jan 4, 2017, 5:11 PM

          @THEMCV If you post it here in a snippet I can probably help. I could find the script myself I suppose, but I’m just being lazy lol.

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          T 1 Reply Last reply Jan 4, 2017, 5:19 PM Reply Quote 0
          • T
            THEMCV @Tom Elliott
            last edited by Jan 4, 2017, 5:19 PM

            @Tom-Elliott

            #!/bin/bash
            
            #----- MySQL Credentials -----#
            snmysqluser="root"
            snmysqlpass=""
            snmysqlhost="10.4.200.150"
            # If user and pass is blank, leave just a set of double quotes like ""
            # if the db is local, set the host to just double quotes "" or "127.0.0.1" or "localhost"
            
            
            #----- Begin Program -----#
            
            selectAllImageIDs="SELECT imageID FROM images ORDER BY imageID"
            selectLowestImageID="SELECT imageID FROM images ORDER BY imageID ASC LIMIT 1"
            selectHighestImageID="SELECT imageID FROM images ORDER BY imageID DESC LIMIT 1"
            
            options="-sN"
            if [[ $snmysqlhost != "" ]]; then
                   options="$options -h$snmysqlhost"
            fi
            if [[ $snmysqluser != "" ]]; then
                   options="$options -u$snmysqluser"
            fi
            if [[ $snmysqlpass != "" ]]; then
                   options="$options -p$snmysqlpass"
            fi
            options="$options -D fog -e"
            
            
            #Information gathering.
            lowestID=$(mysql $options "$selectLowestImageID")
            highestID=$(mysql $options "$selectHighestImageID")
            newAutoIncrement=$((highestID + 1))
            
            
            ####### Basic logic flow ########
            
            #If there is an image id of 1, move it to the new auto increment number.
            #After re-numbering is complete, the new auto increment number will not be taken.
            #Then reset the auto-increment to the new auto increment number, which is the first free number.
            
            
            
            #Move any images that have an ID of 1 to the next free number.
            if [[ "$lowestID" -eq "1" ]]; then
               echo "-------------------"
               echo "Attempting to change Image ID $lowestID to $newAutoIncrement"
               mysql $options "UPDATE images SET imageID = $newAutoIncrement WHERE imageID = $lowestID"
               mysql $options "UPDATE imageGroupAssoc SET igaImageID = $newAutoIncrement WHERE igaImageID = $lowestID"
               mysql $options "UPDATE hosts SET hostImage = $newAutoIncrement WHERE hostImage = $lowestID"
               echo "Attempt completed"
            fi
            
            
            #Re-number all images sequentially.
            count=1
            mysql $options "$selectAllImageIDs" | while read imageID; do
               echo "-------------------"
               echo "Attempting to change Image ID $imageID to $count"
               mysql $options "UPDATE images SET imageID = $count WHERE imageID = $imageID"
               mysql $options "UPDATE imageGroupAssoc SET igaImageID = $count WHERE igaImageID = $imageID"
               mysql $options "UPDATE hosts SET hostImage = $count WHERE hostImage = $imageID"
               echo "Attempt completed"
               count=$((count + 1))
            done
            
            
            #set new auto-increment.
            echo "-------------------"
            highestID=$(mysql $options "$selectHighestImageID")
            newAutoIncrement=$((highestID + 1))
            echo "Attempting to change the auto_increment for the images table to $newAutoIncrement"
            mysql $options "ALTER TABLE images AUTO_INCREMENT = $newAutoIncrement"
            echo "Attempt completed"
            

            Here it is. 🙂 My guess would be to change the SELECT imageID from images to SELECT snapinID from snap ins… but I’m taking a wild guess. 😛

            T 1 Reply Last reply Jan 4, 2017, 5:26 PM Reply Quote 0
            • T
              Tom Elliott @THEMCV
              last edited by Tom Elliott Jan 4, 2017, 11:38 AM Jan 4, 2017, 5:26 PM

              @THEMCV

              #!/bin/bash
              
              #----- MySQL Credentials -----#
              snmysqluser="root"
              snmysqlpass=""
              snmysqlhost="10.4.200.150"
              # If user and pass is blank, leave just a set of double quotes like ""
              # if the db is local, set the host to just double quotes "" or "127.0.0.1" or "localhost"
              
              
              #----- Begin Program -----#
              
              selectAllSnapinIDs="SELECT sID FROM snapins ORDER BY sID"
              selectLowestSnapinID="SELECT sID FROM snapins ORDER BY sID ASC LIMIT 1"
              selectHighestSnapinID="SELECT sID FROM snapins ORDER BY sID DESC LIMIT 1"
              
              options="-sN"
              if [[ $snmysqlhost != "" ]]; then
                     options="$options -h$snmysqlhost"
              fi
              if [[ $snmysqluser != "" ]]; then
                     options="$options -u$snmysqluser"
              fi
              if [[ $snmysqlpass != "" ]]; then
                     options="$options -p$snmysqlpass"
              fi
              options="$options -D fog -e"
              
              
              #Information gathering.
              lowestID=$(mysql $options "$selectLowestSnapinID")
              highestID=$(mysql $options "$selectHighestSnapinID")
              newAutoIncrement=$((highestID + 1))
              
              
              ####### Basic logic flow ########
              
              #If there is a snapin id of 1, move it to the new auto increment number.
              #After re-numbering is complete, the new auto increment number will not be taken.
              #Then reset the auto-increment to the new auto increment number, which is the first free number.
              
              
              
              #Move any snapins that have an ID of 1 to the next free number.
              if [[ "$lowestID" -eq "1" ]]; then
                 echo "-------------------"
                 echo "Attempting to change Snapin ID $lowestID to $newAutoIncrement"
                 mysql $options "UPDATE snapins SET sID = $newAutoIncrement WHERE snapinID = $lowestID"
                 mysql $options "UPDATE snapinGroupAssoc SET sgaSnapinID = $newAutoIncrement WHERE sgaSnapinID = $lowestID"
                 #mysql $options "UPDATE hosts SET hostImage = $newAutoIncrement WHERE hostImage = $lowestID"
                 echo "Attempt completed"
              fi
              
              
              #Re-number all snapins sequentially.
              count=1
              mysql $options "$selectAllSnapinIDs" | while read snapinID; do
                 echo "-------------------"
                 echo "Attempting to change Snapin ID $snapinID to $count"
                 mysql $options "UPDATE snapins SET sID = $count WHERE sID = $snapinID"
                 mysql $options "UPDATE snapinGroupAssoc SET sgaSnapinID = $count WHERE sgaSnapinID = $snapinID"
                 #mysql $options "UPDATE hosts SET hostImage = $count WHERE hostImage = $imageID"
                 echo "Attempt completed"
                 count=$((count + 1))
              done
              
              
              #set new auto-increment.
              echo "-------------------"
              highestID=$(mysql $options "$selectHighestSnapinID")
              newAutoIncrement=$((highestID + 1))
              echo "Attempting to change the auto_increment for the snapins table to $newAutoIncrement"
              mysql $options "ALTER TABLE snapins AUTO_INCREMENT = $newAutoIncrement"
              echo "Attempt completed"
              

              Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

              Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

              Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

              Wayne WorkmanW mtanigawaM 3 Replies Last reply Jan 5, 2017, 2:31 AM Reply Quote 3
              • Wayne WorkmanW
                Wayne Workman @Tom Elliott
                last edited by Jan 5, 2017, 2:31 AM

                @Tom-Elliott Good work. I’ll get this tested and into the fog community scripts repository.

                Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                Daily Clean Installation Results:
                https://fogtesting.fogproject.us/
                FOG Reporting:
                https://fog-external-reporting-results.fogproject.us/

                T 1 Reply Last reply Jan 5, 2017, 1:10 PM Reply Quote 0
                • T
                  Tom Elliott @Wayne Workman
                  last edited by Jan 5, 2017, 1:10 PM

                  @Wayne-Workman I’ll see about editing this script to take the more common elements that might need the id’s re-adjusted and take the table argument (or array of tables if you wanted to.

                  This way we have a more of a “generic” script that can be used for the whole purpose of re-id’ing tables.

                  The idea, ultimately, would be something like:

                  ./updateTableIDs "snapins" or ./updateTableIDs "images snapins"

                  This way we have a script that could work on any table to renumber/factor. Initially it would probably only operate upon single tables. Once that’s been hashed out, work on incorporating multiple table adjustments.

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                  Wayne WorkmanW 1 Reply Last reply Jan 5, 2017, 2:04 PM Reply Quote 0
                  • Wayne WorkmanW
                    Wayne Workman @Tom Elliott
                    last edited by Wayne Workman Jan 5, 2017, 8:05 AM Jan 5, 2017, 2:04 PM

                    @Tom-Elliott Instead of arguments, how about a script that just re-numbers all the IDs by default. Locations too.

                    Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                    Daily Clean Installation Results:
                    https://fogtesting.fogproject.us/
                    FOG Reporting:
                    https://fog-external-reporting-results.fogproject.us/

                    1 Reply Last reply Reply Quote 0
                    • mtanigawaM
                      mtanigawa @Tom Elliott
                      last edited by Jan 16, 2017, 1:36 PM

                      @Tom-Elliott @Wayne-Workman @THEMCV

                      Thanks for this. Worked successfully for me. Will be trying the image ID one once next years image(s) are done. Thank you again!

                      1 Reply Last reply Reply Quote 1
                      • Wayne WorkmanW
                        Wayne Workman @Tom Elliott
                        last edited by Wayne Workman Jan 16, 2017, 10:20 PM Jan 17, 2017, 2:15 AM

                        @Tom-Elliott The script you posted had a few issues, I’ve fixed them up. A mistyped variable in the first loop, and I added code to update the snapinAssoc IDs too so those aren’t lost. I’ve submitted a pull request.

                        All, the improved script will be available here:
                        https://github.com/FOGProject/fog-community-scripts

                        This is just a hold-over honestly. We need a big and comprehensive script to just cleanup and re-order everything. Locations, images, snapins, groups, everything - as well as running cleanup commands that we know fixes stuff and can’t hurt but can only help.

                        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                        Daily Clean Installation Results:
                        https://fogtesting.fogproject.us/
                        FOG Reporting:
                        https://fog-external-reporting-results.fogproject.us/

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post

                        223

                        Online

                        12.0k

                        Users

                        17.3k

                        Topics

                        155.2k

                        Posts
                        Copyright © 2012-2024 FOG Project