The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
So, i'm writing a script to backup files, and then compress them (where in I will then have it saved to a removable hard drive). I'm fairly new to *nix and scripting in general, but so far i'm testing this, and it kinda works. My concern is there might be a better way to do things, it seems there always is. So if any Linux/Unix guys would kindly offer advice and or wisdom, i'd be happy to hear it.
Anyways, here it is.
#!/bin/sh
#
# This is a backup script.
#
cp - r /home /Backup
cp -r /etc/passwd /Backup
cp -r /var/mail /Backup
cp -r /var/www /Backup
cp -r /var/logs /Backup
tar -cjvf /Backup `date +%F-%H-%M`.tar.bz2 /mnt/sda01 >> /var/log/backuplog
throw that in a cron and you got a decent backup system. maybe use cp -rf instead of just recursive too. oh and maybe clear the backup directory after the tar is made depending on how big it is.
throw that in a cron and you got a decent backup system. maybe use cp -rf instead of just recursive too. oh and maybe clear the backup directory after the tar is made depending on how big it is.
Well, with that `date` stuff, it'll name the tar according to the Day/Hour/Minute, so I can search'em better. That whatcha meant? Yeah, this is all gonna be a cron job when i'm done. Thanks for the help
By "Redhat 5.0" I assume you mean RHEL 5, as opposed to the very old pre-Fedora Red Hat 5?
If I were you I would consider using rsync. My first problem with your current solution is that you're not keeping the paths intact. So while you may understand that the logs folder in your backup directory is from /var/logs, I would personally make it so that when they are copied to the backup folder it will be as /Backup/var/logs. Your current script also needlessly copies files that already exist and are possibly unchanged, which rsync won't do.
If you wanted to copy recursively and preserve permissions, you could do:
rsync -aR /path/to/src /Backup/
-R means relative paths, which means that it will recreate the full path of the source in the target directory. So you'd have "/Backup/path/to/src" in the previous example. -r is for recursive copying, but it is implied by the -a option (which is kind of similar to what cp -a does).
Another rsync option to consider is --delete. It tells rsync to delete files in the target directory that doesn't exist in the source directory. If you delete a movie or something from your home directory it will also delete that from your backup directory. That'll cut down on the space your backups take by not backing up something that is already archived from another day. While you could also delete the contents of /Backup after its contents are archived to do the same thing, not doing so and using rsync with --delete will make your backups complete quicker since you aren't copying unchanged data that already exists.
Barrakketh on
Rollers are red, chargers are blue....omae wa mou shindeiru
Posts
your tar line looks a little funny to me, but i assume that works for you?
#tar -czvf `/mnt/sda01/`date +%F-%H-%M`.tar.gz >> /var/log/backuplog
throw that in a cron and you got a decent backup system. maybe use cp -rf instead of just recursive too. oh and maybe clear the backup directory after the tar is made depending on how big it is.
Well, with that `date` stuff, it'll name the tar according to the Day/Hour/Minute, so I can search'em better. That whatcha meant? Yeah, this is all gonna be a cron job when i'm done. Thanks for the help
Edit: Ah, I see what ya did there. My bad.
If I were you I would consider using rsync. My first problem with your current solution is that you're not keeping the paths intact. So while you may understand that the logs folder in your backup directory is from /var/logs, I would personally make it so that when they are copied to the backup folder it will be as /Backup/var/logs. Your current script also needlessly copies files that already exist and are possibly unchanged, which rsync won't do.
If you wanted to copy recursively and preserve permissions, you could do:
-R means relative paths, which means that it will recreate the full path of the source in the target directory. So you'd have "/Backup/path/to/src" in the previous example. -r is for recursive copying, but it is implied by the -a option (which is kind of similar to what cp -a does).
Another rsync option to consider is --delete. It tells rsync to delete files in the target directory that doesn't exist in the source directory. If you delete a movie or something from your home directory it will also delete that from your backup directory. That'll cut down on the space your backups take by not backing up something that is already archived from another day. While you could also delete the contents of /Backup after its contents are archived to do the same thing, not doing so and using rsync with --delete will make your backups complete quicker since you aren't copying unchanged data that already exists.