AIX: Using backsnap command to snapshot backup filesystems
brian_s 270002K5X3 Visits (11480)
Not only does backsnap have one of the coolest command names in AIX, it can be a very useful command for backing up filesystems that are in use.
backsnap can create a snapshot, mount the snapshot, backup the snapshot, and remove the snapshot, all in a single command. When you read the backsnap man page, you might incorrectly get the impression that it only backs up to devices such as tape drives. However, this is not the case, backsnap can also write the backups out as normal files.
You might be wondering when you would use a snapshot backup versus when you would just use tar or the backup command. The downside to tar and backup is that if the data is in use during the backup chances are your backup is invalid. For example, if you need to backup a filesystem that contains a database that is up and running there is little chance you would be able to recover a backup taken with tar or backup.
When you take a snapshot of a filesystem it creates a checkpoint where everything is frozen at that point in time. Any further changes to the data that was present when the snapshot was created is now written to the snapshot filesystem. This allows for a point in time checkpoint and also allows for the application to remain up and running and making changes. Snapshots allow for point in time backups to be created for filesystems with databases that are changing.
What I like about backsnap is that it will do all of the following:
-Step 1: Create a logical volume for the snapshot
-Step 2: mount the snapshot
-Step 3: backup the snapshot
-Step 4: Optionally delete delete the snapshot logical volume.
For example, if you wanted to do a snapshot backup of the /test filesystem and back it up to a file named /tmp/test_backup you could run something like:
backsnap -m /testbackup -R -s size=128M -q -i -f /tmp/test_backup /test
Lets break down the command arguments one at a time:
-m /testbackup This is the temporary mount point where the snapshot will be mounted while it is backed up (Step #2 in list above).
-R This tells backsnap to delete the snapshot logical volume after the backup (Step #4 in list above).
-s size=128M This is the size of the snapshot logical volume that will be created (Step #1 in list above). The size needed will vary depending on the size of your original filesystem, how much the data is changing during the backup, and how long backsnap will take to backup. To be on the safe side, if you have the available space I would recommend setting this to be between 10% - 20% of the size of the filesystem being backed up.
-q This prevents you being prompted to get the media ready which wouldn't make sense in our case since we are backing up to a file
-i Specifies files should be backed up by name
-f /tmp/test_backup The file where the backup should be saved to. (Step #3 in list above)
/test The filesystem to backup
When the command completes you will be left with a backup file /tmp/test_backup.
To restore the backup file, you would simply run restore -q -x -f test_backup which will extract the "test_backup" file (created by backsnap) in to the current directory.
One thing to mention about these types of backups is that they are considered "crash consistent". Let me explain this with an example. A snapshot backup is taken of a database. Later on, the snapshot backup is restored and the database is restarted. From the databases perspective, it appears as if the server had the power cord pulled on it while it was up and running. If you think about what is happening, this will make sense. Basically the "point in time" of a snapshot backup is no different from a point in time when the power plug is pulled on the server because the state of the files on the disk would be identical in either scenario - everything is how it was at that point in time and in both scenarios the database did not get an opportunity to shut down cleanly. The good news is that most data