Difference between revisions of "Network Shared Pacman Cache"

From ArchWiki
Jump to: navigation, search
(removed NFS and SSHFS specific information; the explanation for that should be on the appropriate nfs or sshfs page; so I made a reference to those)
m (rm all traces of [unstable] (and other cruft))
Line 5: Line 5:
 
Then, to share the actual packages you should mount <code>/var/cache/pacman/pkg</code> from your server to <code>/var/cache/pacman/pkg</code> on every client machine.
 
Then, to share the actual packages you should mount <code>/var/cache/pacman/pkg</code> from your server to <code>/var/cache/pacman/pkg</code> on every client machine.
  
If you also want to have shared package databases you will need to mount <code>/var/lib/pacman/{current,extra,testing,community,unstable}</code> in the same way.
+
If you also want to have shared package databases you will need to mount <code>/var/lib/pacman/{core,extra,testing,community}</code> in the same way.
 
'''Warning:''' do not mount <code>/var/lib/pacman/local</code> as it contains your actual [local] database!
 
'''Warning:''' do not mount <code>/var/lib/pacman/local</code> as it contains your actual [local] database!
  
Line 14: Line 14:
  
 
===Note:===
 
===Note:===
As of version 3.1 "pacman -Sc" changed behavior. It does no longer remove all outdated package files but all package files which are not installed on the machine the command was issued on. Because Pacman can't predict what packages are installed on all machines that share the cache, you will end up deleting files you don't want to delete. If you want to clean up your cache to only keep the newest packages you will have to do this by yourself. I use this script (as always without any warranty):
+
As of version 3.1 "pacman -Sc" changed behavior. By default it does no longer remove all outdated package files but all package files which are not installed on the machine the command was issued on. Because Pacman can't predict what packages are installed on all machines that share the cache, you will end up deleting files you don't want to delete. If you want to clean up your cache to only keep the newest packages you will have to put <code>CleanMethod = KeepCurrent</code> in the [Options] section of /etc/pacman.conf.
 
+
# !/bin/bash
+
# script cleans pacman cache by comparing existing version of a package
+
# to newest version of package available according to pacman-db
+
# WARNING! THIS SCRIPT WILL DELETE EVERY FILE IN /var/cache/pacman/pkg
+
# THAT IS NOT IN THE PACMAN-DB OR THAT DOES NOT FOLLOW THE CURRENT NAMING
+
# CONVENTIONS: <PACKAGENAME>.<VERSION>.<ARCHITECTURE>.pkg.tar.gz !!!
+
#
+
arc=$(uname -m)
+
for fn in $(ls /var/cache/pacman/pkg);do
+
    # strip off .pkg.tar.gz
+
    f=${fn/%\.pkg\.tar\.gz/}
+
    # strip off architecture if given in package name
+
    if echo $f | grep -q $arc; then
+
        f=${f/%$arc/};f=${f/%-/}
+
    fi
+
    # now divide string into version and package name as used by pacman -Si
+
    pk=$f;v=$f;pk=${pk%-*};pk=${pk%-*};v=${v/$pk};v=${v/-}
+
    # query pacman-database to get current version of package and delete cached version if it is older
+
    if ! pacman -Si $pk | grep -q $v ; then
+
        rm -v /var/cache/pacman/pkg/$fn
+
    fi
+
done
+
# end of file
+
  
 
[[Category:Package management (English)]]
 
[[Category:Package management (English)]]
 
[[Category:HOWTOs (English)]]
 
[[Category:HOWTOs (English)]]

Revision as of 17:24, 14 December 2008

In order to share packages between multiple computers you can simply share /var/cache/pacman/ using any network-based mount protocol. This guide shows you how to use shfs or sshfs to share a package cache plus the related library-directories between multiple computers on the same local network.

First, install any network-supporting filesystem; for example sshfs, shfs, ftpfs, smbfs or nfs

Then, to share the actual packages you should mount /var/cache/pacman/pkg from your server to /var/cache/pacman/pkg on every client machine.

If you also want to have shared package databases you will need to mount /var/lib/pacman/{core,extra,testing,community} in the same way. Warning: do not mount /var/lib/pacman/local as it contains your actual [local] database!

You may put the appropriate lines in your /etc/fstab file

Note: using shared database can be slow, depending on network filesystem type and LAN load. Tip: if you want to use sshfs or shfs you should consider reading Using SSH Keys.

Note:

As of version 3.1 "pacman -Sc" changed behavior. By default it does no longer remove all outdated package files but all package files which are not installed on the machine the command was issued on. Because Pacman can't predict what packages are installed on all machines that share the cache, you will end up deleting files you don't want to delete. If you want to clean up your cache to only keep the newest packages you will have to put CleanMethod = KeepCurrent in the [Options] section of /etc/pacman.conf.