In this video, Kevin Dankwardt, demonstrates use of tar and cpio for backups. He cautions you about being careful with cpio in particular because it can overwrite using absolute path names and if run as root can be disastrous.
- [Instructor] Let's talk about using cron to do a backup. Well if you're going to do a backup daily or hourly then your Lenox system might be already configured to make that pretty convenient, because it already runs stuff usually hourly and daily. If you go to etc and you list grep cron, you'll see a number of things. You'll see the anacrontab, if you look at that, down on the bottom there it's pretty cryptic but essentially the one for the cron.daily line there says run everyday, a delay of five minutes, we're calling it cron.daily and it's going to do a nice command.
So it won't interfere with other stuff and we do the run-parts command, you can look at that, that's actually a script in bin. And it's going to run the cron.daily program. It's going to run the stuff in cron.daily all the programs in cron.daily. So if we go to cron.daily, and the anacron also says don't start before three in the morning, stuff like that.
So we go here, and it's going to run all these scripts. You can see this one's set up to rotate my logs and the mlocate is what's used so you can use the locate command and so forth. So we could just write a new script here to do backups. So let's just call it backupstuff.sh. We'll make it a script and what do we want to do? Maybe we want to create a compressed tar ball in a directory called backups and we'll call it bu-' the date command output .tar.bz2.
We need those double quotes in there because that date command when that runs is going to have spaces in it. And what are we going to backup? We're going to backup we'll say /home/guest. Alright so we're going to create in backups a tar ball named bu and the date and time .tar.bz2. That's what in /home/guest. And because we put this in cron.daily, and we make it executable, it will run everyday.
Simple as that. Now I really don't want that to happen so I'm going to remove it before I forget. There we go. Now let's look at rsync, let's see. Got a little directory here in tmp called backups, got a couple files in it. Let's say we want to make a backup of this directory. Well rsync will copy the contents of a directory.
And then the next time you copy it, it will look to see what's different and it will just have to copy over stuff to make the changes. So if you have a lot of stuff and only a little bit changed, rsync is really fast, rsync is a handy way to essentially make a remote copy and keep it up to date with a local copy. So let's see. There's tmp/adir that's empty, let's use rsync to make a copy of what we have in backups, so we're going to do archive mode for both so it's going to copy softlinks and stuff like that and we're going to copy backups to /tmp/adir.
And it says it copied over, backup stuff.cpio and backups x.cpio. And if we look at /tmp/adir, we got the sub directory backups. If we use rsync slightly differently if the thing we're copying from is a directory, we put a slash at the end, this is really pretty subtle, then we get what was in the directory not a copy of the directory. So with a slash it means copy what's in the directory, without the slash it means copy the directory.
Now let's go into backups and let's touch a new file. Go back up here, so now the only thing different because I didn't change the stuff.cpio or x.cpio but I added a new file, the only different is new file. If we do this rsync again, it knows all it has to do is copy over new file. That's the cool thing about rsync.
- Partitioning storage
- Creating, mounting, and unmounting file systems
- Formatting file systems
- Making volumes with LVM
- Adding storage security
- Managing swap spaces
- Backing up and recovering Linux storage systems
- Working with networked file systems like NFS and SSHFS