# Arch Linux System Maintenance (简体中文)

翻译状态： 本文是英文页面 Arch_Linux_System_Maintenance 的翻译，最后翻译时间：2014-04-12，点击这里可以查看翻译后英文页面的改动。

Regular system maintenance is necessary for the proper function of Arch over a period of time. Timely-maintenance is a practice many users get accustomed to.

## Error checking

Warning: The author of this section is not an expert on this procedure

Periodically look into `/var/log/` and look at:

- `errors.log`
- The tail end of `everything.log`
- `Xorg.0.log` and look for (EE) and (WW)
- Check to see that all units are loaded by systemd with `systemctl --failed`.

## Package tasks

Having the correct, up-to-date, and configured-properly packages are a key system maintenance.

### System stability regardings

Package tasks that are grouped with system stability are covered in Enhance system stability#Maintaining_Arch.

### Orphaned packages

Packages that were once dependent on another package but no longer are... can be removed with:

    pacman -Rcs $(pacman -Qtdq)

### Unused packages

To keep a lighter system and easier to maintain, rid the system of old, unused packages. You can look at explicitly installed packages (i.e. non-dependencies) for official packages by doing:

    pacman -Qqe | grep -v "$(pacman -Qqm)" | less

and for packages not installed from official repositories by doing:

    pacman -Qqm

### Package cache clean

Pacman stores it's downloaded packages in `/var/cache/pacman/pkg/` and every now and then it's a good idea to trim it down. You can do this with pacman with `pacman -Sc` which will remove all downloaded packages except the currently installed version. To automate this task it can be put in one's chronological table (see Optimize pacman database below).

If desiring to have more than the currently installed package available consider using pkgcacheclean which can leave multiple versions behind.

### Optimize pacman database

Pacman includes `pacman-optimize` a tool to optimize pacman's database which is stored in a set of small files. `pacman-optimize` will attempt to put the files on one location of the hard disk to improve access speed.

    # mm  hh  DD  MM  W /path/program [--option]...  ( W = weekday: 0-6 [Sun=0] )
      @monthly          /usr/bin/pacman -Sc
      @monthly          /usr/bin/pacman-optimize

## Housekeeping

General duties to keep things tidy.

### Cruft trimming

Root directory (`/`) files are generally placed by the package manager and should be generally kept that way for ease of maintenance. If needed to have something installed to the root directory (i.e. not `/home`) consider creating a package for it. To tell if any extraneous files exist:

Create a filelist of package-known files by:

    for p in $(pacman -Qq); do pacman -Qql $p; done > pkgs-filelist.txt
    sed -i 's#/$##g' pkgs-filelist.txt # removes trailing slashes
    sort -u pkgs-filelist.txt -o

And create filelist of the root directory files (omit temporary file systems [`/dev`, `/proc`, `/run`, `/sys`; `/home`; other mounts `/media`, `/mnt`; root user directory `/root`; and temporary directories `/tmp` and some in `/var`]):

    find / -not -path "/dev/*" -not -path "/proc/*" -not -path "/run/*" -not -path "/sys/*" -not -path "/home/*" -not -path "/media*" -not -path "/mnt/*" -not -path "/root/*" -not -path "/tmp/*" -not -path "/var/cache/cups*" -not -path "/var/cache/fontconfig*" -not -path "/var/cache/pacman/pkg/*" > root-filelist.txt
    sort -u root-filelist.txt -o root-filelist.txt

These can get quite large so a good diff editor is needed, `vimdiff` will do:

    vimdiff pkgs-filelist.txt root-filelist.txt

Old configurations will be left at times, get rid of those and any other cruft and trash. Also look at `/var` and make sure there isn't some accumulation there. `/var` is the location where logs are kept and other constantly changing data. Go through and see if anything is getting large:

    du -sh /var/*

### Home clutter trim

Go through the files in the `/home/$USER`'s directory... all of them. If a file hasn't been used in quite some time and probably will never be needed, consider getting rid of it. Down the road it may be good not to have to go through 100 directories looking for the one file you need in `~/.config/` for example. Also look for configurations that also support `~/.config/` now and move them there as to help reduce clutter.

## Backup

Numerous programs exist in the repositories to back up the system with. Regular backups often are not necessary; however, one day it seems that everyone runs into the "OMG, no" moment. rsync is probably the most used program and it's invocation is basic:

    rsync -a src_dir dst_dir

Backups of the system should be done from a live medium (like an install cd) unless one knows what one is doing.

Category:

- System administration (简体中文)