root cron script using cp commands doesn't copy all files
I suspect I'm missing something obvious but I'm stumped. The following script, called SystemBackup
cp -purL /home /archive5/LinuxBackup/Tree
cp -purL /etc /archive5/LinuxBackup/Tree
cp -purL /var /archive5/LinuxBackup/Tree
cp -purL /root /archive5/LinuxBackup/Tree
rm -d -r /archive5/LinuxBackup/Tree/var/cache/beagle/indexes
when run under Ubuntu 8.04 as
seems to copy all the files in the source directories to my backup area on an external hard drive (directory "Tree" having been emptied before hand)
but when run as a root crontab entry (again having emptied "Tree" first)
50 16 * * * /home/user/SystemBackup
it copied some of the sub-folders under home, etc, var, root but not all (maybe only a third). I don't see any consistency vis permissions or ownership between what it does and does not copy.
I also modified the cp -purL /var to cp-vpurL /var and piped the output to my /home/user folder. It just seems to only be copying some of the files. I don't see any error messages.
I've googled but similar situations seem to be based on not running as root, but I checked that by substituting /usr/bin/id for ./SystemBackup in the crontab entry and piping the output to my /home/user folder. It showed that I was running as root.
I know I'm going to kick myself, but I just don't have a handle on this (and at best I'm intermediate Linux skills, more likely seasoned newbie). Any ideas? Need more details?
I am more concerned that the name of the script is called systembackup. Have you tested this assuming your system files are lost or attempted a restore on a new hard drive? Me thinks you do not have enough to get back to where you want?
2) so can you advise what normal backup software you have tried and why they do not meet your requirements. And while I am being nosy.....have you copied stuff to tape drive or external drive or dvdrws?
3) I am not perfect btw....I use partimage and the image is backed up to dvdrw Its not an incremental backup so you need to take some risks and backup key files separate to partition....but I am more confident I can rebuild onto a new hard drive....as I have done so in the past.
4) others like dd if they do not use dedicated backup software
5) if you like scripts.....instead of software...take a peek at this ...it could suit ?
Hi aus9, thanks for the reply.
Well, when I was on Suse I used its backup which created a tarball. Back in Jan 08 when I switched to Kubuntu I posted here at LQ asking for "best practice" since it didn't seem to have an equivalent backup. See the thread: http://www.linuxquestions.org/questi...actice-611349/
From advice received in that thread I created the script I posted which *seems* to have worked fine for over a year. Note that my data files are on separate partitions and are handled differently. This "SystemBackup" is only meant to provide a way to get back the state of Linux itself and/or to provide a reference point if I mess up some config file. Granted, I haven't had to recover, nor have I had a fire drill to simulate same.
After posting this question I realized I could have stepped outside the box and changed to use rsync. The cp command looked like it should be fine for my simple needs.
I'm not sure if it was my recent switch to Ubuntu 8.04, or changing the destination to a USB external drive instead of a Samba share, or maybe my script has never *really* been working (in the sense that the "u" switch and my not deleting the destination as a matter of course could mean it stopped working months ago and I didn't realize it until "testing" my new script to a new, empty destination).
-- woops nothing to see here --
Hi, I would look into rsync for backups rather than cp.
rsync won't care if the file is protected or not.
My original reference is gone, here is a plain text copy, check the man page for rsync for more...
Thanks Glenn. I was away from home, just saw your advice. I will work on converting my simple script from cp to rsync and then retest. Thanks for the "Fun with rsync" doc, plus (as you say) I'll look at the man page also.
*** EDIT ***
I have now changed the original script where it said "cp -purL" to have "rsync -a --delete" and rerun both the sudo version from the command line, and the same script as a root cron entry, deleting the output folder first so they both started clean. Both give the correct results (i.e., number of files and total size of the four source folders and their backed-up versions match). Thanks for the advice and for helping me to learn!
The next time you run it it should only update files that have changed,
like a back program would.
The nice part is that it will write to ntfs too and keeping permissions is handy.
Some one told me about rsync, I'm just passing it on. That's community.
|All times are GMT -5. The time now is 06:47 PM.|