• MySQL知识库 :: backup
  • How to make unique IDs for backups?

  • Discussion

    Each online MySQL Cluster backup receives a unique identification number. This is to ensure that there is a history of activities in the backup directory. However, this can causes problems. For example, if a system restarts, this ID counter is reset and starts again at the number 1, causing problems if you didn't move earlier backups.

    Solution

    The best method is after each online backup operation to move the created backup directory to another location (e.g. a file server). This will ensure that there can never be a problem with duplicate backup IDs on the data nodes themselves. Additionally, you can generate your own backup IDs and pass them to the the START BACKUP statement using the ndb_mgm client tool. As of MySQL Cluster versions 6.2.17, 6.3.23, and 7.0.3, this ID has an upper limit of 4294967296 (232). Earlier versions only support a maximum of 2147483648 (231).

    One example of how to generate your own backup ID is to use Unix or POSIX time. The advantage of this is that it is already a 32 bit number and each time you run START BACKUP it will be the current time, which is unique unless you temper with the system clock. You would enter something like the following from the command-line:

    TS=`date +%s` && ndb_mgm -e "START BACKUP $TS"
    ..
    Node 3: Backup 1237979830 started from node 1
    Node 3: Backup 1237979830 started from node 1 completed
    ..

    Another example would be to use the actual date and hour a backup is made. The advantage of this is that it's easier to read and one can see directly from which day the backup was made. The following example, however, will only work once per hour—it's entered from the command-line, as well:

    TS=`date +%Y%m%d%H` && ndb_mgm -e "START BACKUP $TS"
    ..
    Node 3: Backup 2009032512 started from node 1
    Node 3: Backup 2009032512 started from node 1 completed
    ..

    There are many possible ways to generate backup IDs and not be restricted to timestamps. You could generate a counter which is stored in a central database running on your backup server. How you generate an ID is up to you.