561 564




Using Linux:System Maintenance






-->















Previous
Table of Contents
Next




This command archives many of the files unique to most systems.



The Linux Filesystem Standard describes the general layout of most Linux systems
For more information about the standard configuration of most Linux filesystems, you can review the Linux Filesystem Standard (often abbreviated FSSTND) at http://www.pathname.com/fhs/.

Again, if you cannot back up everything, make sure you are backing up everything important.

Once you have a full backup, you can begin to take advantage of the tar and find command options to make backups of files that have changed since the last full backup (incremental backups).
To track the date of the last backup, sometimes it makes sense to store it in a file:


#ls -l lastarchive.tar | cut -f6-8 > lastarchive.date


If you are backing up with tar, the -N option backs up only files with more recent access times than the date provided:


#tar -cz -g archlog.txt -N DATE -V 'latest backup’ /home


The -g option creates a log file archlog.txt, which contains the archive time and a list of the directories archived. -V electronically labels the archive latest backup. The -N option specifies that tar is only to back up files newer than DATE, where the date is entered in the same format as the date command’s. So, if you know the date of the last archive, you could use this date to generate an incremental backup. (Actually, this command is a bit redundant. The -g archlog option looks for an existing file named archlog and, using the date recorded from the last backup in this file, instructs tar to archive only files newer than that date. So this command assumes you have not yet created a -g archlog file.)
If you need to archive files that could be anywhere on the system, the find command comes in handy:


#find / -atime -1 -print > /home/backuplists/todaysfiles
#tar -cvz -f /dev/rft0 -T /home/backuplists/todaysfiles


These commands place an archive of files accessed within the last 24 hours on the tape mounted at /dev/rft0. (Make sure to change the tape each day if you need to store more than one day’s backup.)
You can use the crontab feature to avoid having to run this backup manually:


* 3 * * * find / -atime -1 -print > \
/home/backuplists/todaysfiles; mt -f /dev/rft0 rewind; \
tar -cvz -f /dev/rft0 -T /home/backuplists/todaysfiles


You can also use shell scripts to automate backups. A simple example would be to take the cron bash commands in the preceding example and type them into a shell script called todaysbu. You could then just add the following to crontab:


* 3 * * * /home/backupscripts/todaysbu



SEE ALSO

•  For more information about using dates and crontab with Linux, see page 429.
•  For more information about using shell scripts to automate tasks, see page 365.
•  For more information about cron, see page 435.



Performing File System Maintenance
It’s good to be in the habit of snooping around your system a little for unnecessary files. Besides keeping space free, it familiarizes you with the layout of your directories, and the way users (including you) are utilizing the system.

Deleting Unnecessary Files
In addition to using find to locate files to back up, you can use it to search for files that are no longer needed. After you have found those files, you can delete them from the command line, or use an automated process (crontab entry or shell script) to remove them. (Warning: Make sure you back up any files you may ever need again before removing them.)
For instance, you can search for files belonging to users who no longer have access to the system, archive them to a tape, and delete the originals (make sure your backup is good):


#find / -user tb -print > tbfiles
#tar -cvz -f tbfile.tar.gz -T tbfiles
#find / -user tb -print0 | xargs -r0 rm


The last command line makes use of the xargs utility. xargs processes each argument piped to it and runs a command on that argument. The find print0 option separates filenames with a NULL (0) character instead of a newline, in case some files or directories have a newline in their names (unlikely, but better safe than sorry). The -r0 options tell xargs to expect input separated by NULL characters (0), and make sure the command doesn’t run if the input is a blank line (r). To remove directories, use the following command:


#find / -user tb -print0 | xargs -r0 rmdir


For more information about xargs, see its man page.

SEE ALSO

•  For more information about shell scripts, see page 365.
•  For more information about using crontab, see page 435.
•  For more information about the rm and rmdir commands, see page 42.
•  For more information about the tar command, see page 544.



Undeleting Files
The only way to undelete files with Linux is to use a backup system like tar or taper. There is no Recycle Bin or Trash icon where deleted files are kept indefinitely. To examine archives for a lost file, use the tar command


#tar -tvz -f monthlybackup.tar.gz lostfile(s)


tar lists any files in the monthly backup matching lostfile(s). To restore lost files, create a lost file directory and extract the designated files there (rather than trying to place them back in their original habitat immediately). Sometimes directory permissions or pathnames may have changed, and occasionally someone will have created a new file in the same place, with the same name, as the one you are restoring. Use the following commands:


#cd /home/me/restored_lostfiles
#tar -xvz -f monthlybackup.tar.gz lostfile(s)


Then you can move the files back to the original places after you have verified that no conflicts or problems with file attributes exist.


SEE ALSO

•  For more information about file permissions and attributes, see page 43.
•  For more information about the tar command, see page 544.







Previous
Table of Contents
Next














Wyszukiwarka

Podobne podstrony:
558 561
564,6,artykul
Nuestro Circulo 561 Vladimir Petrov
README (564)
01 (564)
Porownanie 3820 a 561
564 (2)

więcej podobnych podstron