将系统上所有数据都写入磁带机:
#find/-print|cpio–cobB>/dev/st0
将磁带机上的数据还原回来
#cpio–icduv
注解:
由于cpio无法直接读取文件,而需要“每一个文件或目录的路径连同文件名一起”才可以记录下来,因此cpio常与find一起使用,虽不太好用,但却可以备份任何数据,包括/dev/中的任何设备文件
Remotebackups
·Username@hostname:
/path(username为指定的使用者名称,hostname为远程主机)
·tar-czvfxiaofan@example:
/var/host.tar.gz/home
·dump-0ufxiaofan@example:
/var/home.dump/home
Archivingtools:
tar
·tarcanbackuptoafileortapedevice
·SupportsGZIPandBZIP2compression
·Canpreservefilepermissions,ownershipandtimestamps
·Supportsextendedattributes
·Usesrmttowritetoaremotetapedevice
ArchivingTools:
dump/restore
·Backupandrestoreext2/3filesystems
·Doesnotworkwithotherfilesystems
·dumpshouldonlybeusedonunmountedfilesystemsorfilesystemsthatareread-only.
·Candofullorincrementalbackups
·Examples:
Dump-0u-f/dev/nst0/dev/hda2(其中“-0~-9”:
“-0”指的是完全备份;“-1~-9”指的是增量备份)
Restore-rf/dev/nst0
Usingdump
Thedumpcommandcanbedirectedtoread/etc/fstabanddobackupsbasedoninformationitkeepsastowhichfilesystemsneedtobebackedup.
Forexample,
Dump-0u-f/dev/nst1/home
Willdoafullbackupofthe/homefilesystemontothetapedevicenst1.The–uoptionwillupdatethefile/etc/dumpdates,whichwillrecorddumpinformationforfutureusebydump.Afteralevel0backup,dumpwillperformanincrementalbackupeverydayonactivefilesystemslistedin/etc/fstab.
Thecommand:
Dump-4u-f/dev/nst1/home
Willperformanincrementalupdateofallfilesthatchangedsincethelastbackupoflevel3orlower,asrecordedinthe/etc/dumpdatesfile.
Dump-0ufxiaofan@svr:
/dev/nst0/home
Performsaremotebackupusingrmt.Useuser@host:
pathformattospecifytheremoteuser,host,anddevice.SSHcanbeusedasatransportlayerwhen$RSHissettossh.
Usingrestore
Torestoredatabackedupwithdump,makeacleanfilesystem(usingmkfs),mountthefilesystem,andcdtothedirectorywherethefilesystemismounted.Thenruntherestorecommand:
Restore-rf/dev/nst1
ArchivingTools:
rsync
·Efficientlycopiesfilestoorfromremotesystems
·Usessecuresshconnectionsfortransport
·rsync*.confbarney:
/home/joe/configs/
·Fasterthanscp–copiesdifferencesinlikefiles
Rsyncisaprogramthatworksinmuchthesamewaythattheolderrcpdoes,buthasmanymoreoptionsandusesthersyncremote-updateprotocoltogreatlyincreasethespeedoffiletransferswhenthedestinationfilealreadyexists.
Thersyncremote-updateprotocolallowsrsynctotransferjustthedifferencesbetweentwosetsoffilesusinganefficientchecksum-searchalgorithm.Thisutilityisusefulfortaskslikeupdatingwebcontent,becauseitwillonlytransferthechangedfiles.
Usefuloptionstorsync
-ecommand----specifiesanexternal,rsh-compatibleprogramtoconnectwith(usuallyssh)
-a----recurssubdirectories,preservingpermissions,etc.
-r----recurssubdirectorieswithoutpreservingpermissions,etc.
--partial----continuespartiallydownloadedfiles
--progress----printsaprogressbarwhiletransferring
-P----isthesameas--partial--progress
-p----preservepermissions
-A----preserveACLs(implies–p)
-X----preserveextendedattributes(implies–p)
WhatisSoftwareRAID?
·Multipledisksgroupedtogetherinto“arrays”toprovidebetterperformance,redundancyorboth.
·mdadm----providestheadministrationinterfacetosoftwareRAID.
·Many“RAIDLevels”supported,includingRAID0,1,5and6.
·Sparedisksaddextraredundancy
·RAIDdevicesarenamed,/dev/md0,/dev/md1,/dev/md2,/dev/md3andsoon.
ThemostcommandonlyusedRAIDare:
·RAID0orStriping(带区卷):
Twoormoredisksusedtocreateasinglelargehighperformancevolume.Performanceisbetterifdriversofequalsizeareused.Noredundancy,sochanceoffailureisveryhigh.Arraysizeequalsthesumofalldisksinarray.
·RAID1orMirroring:
Twodiskscontainingthesamedataupdatedsimultaneously.Redundancyoffersgoodprotectionagainstdiskfailure.Canslowwriteperformancebuttendstoimprovereadperformance.OnlyRAIDtypethatyoucanplacethe/bootpartitionon.Hotsparediskscanbeusedtoimprovefault-tolerance.Arraysizeequalsthesizeofthesmallestdiskused.
·RAID5:
Threeormorediskwithzeroormorehotspares.Agoodbalancebetweenperformanceandreliability.Redundancyisachievedbysplitting(分区)parity(奇偶性)betweenalldisks,onediskcanbelostwithoutcausingarrayfailure.Bothreadandwritespeedsareusuallyimproved,butincertaincaseswriteperformanceisdramaticallydecreased.ForthisreasonRAID5isoftennotagoodchoicetohostdatabases.
·RAID6,orstripingwithdual(duplicated)distributedparity.SimilartoRAID5exceptthatitimprovesfaulttolerancebyallowingthefailureofanytwodrivesinthearray.Whilethesimultaneousfailureoftwodevicesmaybeanunlikelyevent,RAID6protectsthearrayfromdatalossduringrecoveryofasinglediskfailure,providestheadministratoradditionaltimetoperformrebuilds,improvestheviabilityoflessexpensivedrivesinenterprisestoragesolutions,and,sinceRAIDonlypassivelychecksforbadblocks,protectionfromundiscoveredblockerrors.
Onceanarrayiscreatedit’sdevice,/dev/md0forexample,isusedthesamewayas/dev/hda6or/dev/sda6mayhavebeenusedinanearlierexample.
SoftwareRAIDConfiguration
·CreateanddefineRAIDdevicesusingmdadm
Mdadm-C/de/md0-ayes-l1-n2-x1elements…
·FormateachRAIDdevicewithafilesystem
Mke2fs-j/dev/md0
·TesttheRAIDdevices
·mdadmallowyoutocheckthestatusofyourRAIDdevices
Mdadm--detail/dev/md0
·providesnotificationservicesonthestatus
SoftwareRAIDTestingandRecovery
·Simulating(模拟)diskfailures
Mdadm/dev/md0-f/dev/sda1
·RecoveringfromasoftwareRAIDdiskfailure
·Replacethefailedharddriveandpoweron
·Reconstructpartitionsonthereplacementdrive
·mdadm/dev/md0-a/dev/sda1
·mdadm-r----removethefaileddiskfromthearray
·mdadm,/proc/mdstat,andsyslogmessages
·Disassemble(反汇编)orauto-assemblediskarray
Mdadm-S/dev/md0
Mdadm-A-s
WhatisLogicalVolumeManager(LVM)?
·Alayerofabstractionthatallowseasymanipulationofvolumes.Includingresizingoffilesystems
·Allowreorganizationoffilesystemsacrossmultiplephysicaldevices
·DevicesaredesignatedasPhysicalVolumes
·OneormorePhysicalVolumesareusedtocreateaVolumeGroup
·VolumeGroupsaredefinedwithPhysicalExtentsofafixedsize
·LogicalVolumesarecreatedonVolumeGroupsandarecomposedofPhysicalExtents
·FilesystemsmaybecreatedonLogicalVolumes
CreatingLogicalVolumes
·Createphysicalvolumes
Pvcreate/dev/hda3
·Assignphysicalvolumestovolumegroups
Vgcreatevg0/dev/hda3
·Createlogicalvolumesfromvolumegroups
Lvcreate-L256M-ndatavg0
Mke2fs-j/dev/vg0/data
ResizingLogicalVolumes
·GrowingVolumes
·lvextendcangrowlogicalvolumes
·resize2fscangrowext3filesystemonlineoffline
·Shrinkingvolumes
·Mustbedoneoffline(umount)
·Requiresafilesystemcheck(e2fsck)first
·Filesystemthenreduced(resize2fs)
·Lastly,lvreducecanthenreducethevolume
·VolumeGroupscanbeenlargedwithvgextend
·VolumeGroupscanbereducedwith:
Pvmove/dev/hda3
Vgreducevg0/dev/hda3
LogicalVolumeManagerSnapshots
·SnapshotsarespecialLogicalVolumesthatareanexactcopyofanexistingLogicalVolumeatthetimethesnapshotiscreated
·Snapshotsareperfectforbackupsandotheroperationswhereatemporarycopyofanexistingdatasetisneeded
·SnapshotsonlyconsumespacewheretheyaredifferentfromtheoriginalLogicalVolume
·Snapshots