[arch-general] Updated /var/cache/pacman/pkg old package version removal scripts
David C. Rankin
drankinatty at suddenlinkmail.com
Sun Jan 2 19:07:49 EST 2011
Guys,
I have updated the script that I use to scan /var/cache/pacman/pkg and move old
package versions to /home/backup/pkg-1 (next older version in: pkg-2, then pkg-3
and finally pkg-del). Additions to the script include directory md5sum checks
for new packages (the script skips parsing any directory if there are no
changes) and a disk usage summary at the end showing the size of each directory.
As in the past, there are 2 scripts involved. The script you execute is
'fduparch.sh' which calls fduppkg for each directory. Currently, the only
packages that the script misses are those with number as part of the name like
"mplayer-32663-1". It handles virtually all others without issue.
Grab the scripts here:
http://www.3111skyline.com/dl/Archlinux/scripts/fduparch.sh
http://www.3111skyline.com/dl/Archlinux/scripts/fduppkg
To use the scripts, just download the scripts, make sure they are executable,
and then create soft links to them in /usr/local/bin. I have the links setup as
follows:
fduparch -> /home/david/scr/arch/fduparch.sh
fduppkg -> /home/david/scr/arch/fduppkg
Then just call fduparch to remove duplicates from /var/cache/pacman/pkg and
create the directories under /home/backup. I have it configured to save the last
3 versions of each package in /home/backup/{pkg-1,pkg-2,pkg-3} with any
remaining duplicates dumped in /home/backup/pkg-del to be deleted - manually.
Run fduparch [-h | --help] for a usage summary for both scripts.
I have changed the backup package dir names from pkg-old, pkg-older to just
pkg-1, pkg-2... pkg-del. The script has checks for the pkg-old, pkg-older names
and moves the directories to the new names if you have used a prior version of
the script.
To change the location or number of backup directories, just edit the following
line in fduparch.sh and remove or rename the locations:
DIRLIST=( /var/cache/pacman/pkg /home/backup/pkg-1 /home/backup/pkg-2
/home/backup/pkg-3 /home/backup/pkg-del )
For example to just save just one prior version of your packages and move
everything else to pkg-del, then just do:
DIRLIST=( /var/cache/pacman/pkg /home/backup/pkg-1 /home/backup/pkg-del )
** you need at least 1 directory in addition to /var/cache/pacman/pkg for the
array logic ${#DIRLIST[@]}-1 to work. But beyond that, you can simply change the
name and location of the backup package directories to whatever you want.
The script creates 2 other files. /home/backup/.data/pkgdir-md5.txt to hold the
md5sums for the directories and /home/backup/log/pkgdups.log.bz2 which is simply
a log file of what was moved where. You can change any of this to suit your
taste by editing the variables in the script.
Also, to run the script as your user with sudo, just edit the line:
if [[ $USER == david ]]; then
and change david to your username. Otherwise you will need to run the script as
root for permissions to move packages from /var/cache/pacman/pkg and to create
the /home/backup directory.
The script output (default) shows a brief heading for each directory it
operates on and then provides a disk usage summary at the end:
09:58 archangel:~/arch/pkg> fduparch
calling: 'fduppkg /var/cache/pacman/pkg -d /home/backup/pkg-1 -l pkgdups.log'
Total packages to screen: 1989
Removing duplicates from: /var/cache/pacman/pkg
Duplicates directory: /home/backup/pkg-1
Log file location: pkgdups.log
Verbose mode set: [use -q to stop pkg output | -s to stop all output]
pkg [ 70] binutils dup => binutils-2.20.1-4-x86_64.pkg.tar.xz
pkg [ 308] f-spot dup => f-spot-0.6.2-1-x86_64.pkg.tar.xz
<snip>
11 duplicates moved to /home/backup/pkg-1
<snip operations on other directories>
Duplicate Removal Summary
3.2G /var/cache/pacman/pkg
2.4G /home/backup/pkg-1
2.8G /home/backup/pkg-2
2.4G /home/backup/pkg-3
103M /home/backup/pkg-del
If there are no changes to the files in the directories, then they are skipped
and you are just presented with a summary at the end.
For anyone interested in learning a bit about bash scripting, the scripts are
reasonably commented and cover a broad spectrum of what bash can do.
Enjoy.
--
David C. Rankin, J.D.,P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com
More information about the arch-general
mailing list