]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/upgrade-1.0-store.pl
3 ## Copyright (C) 1996-2021 The Squid Software Foundation and contributors
5 ## Squid software is distributed under GPLv2+ license and includes
6 ## contributions from numerous individuals and organizations.
7 ## Please see the COPYING and CONTRIBUTORS files for details.
13 $USAGE="Usage: $0 swaplog cachedir1 cachedir2 ...\n";
17 $swaplog = shift || die $USAGE;
18 (@cachedirs = @ARGV) || die $USAGE;
19 $ncache_dirs = $#cachedirs + 1;
21 $OLD_SWAP_DIRECTORIES = 100;
22 $NEW_SWAP_DIRECTORIES_L1 = 16;
23 $NEW_SWAP_DIRECTORIES_L2 = 256;
25 $EEXIST = 17; # check your /usr/include/errno.h
28 This script converts Squid 1.0 cache directories to the Squid 1.1
29 format. The first step is to create the new directory structure.
30 The second step is to link the swapfiles from the old directories
31 into the new directories. After this script runs you must manually
32 remove the old directories.
34 Filesystem operations are slow, so this script may take a while.
35 Your cache should NOT be running while this script runs.
37 Are you ready to proceed?
42 exit(1) unless ($ans =~ /^y$/ || $ans =~ /^yes$/);
44 # make new directories
45 foreach $c (@cachedirs) {
48 foreach $d1 (0..($NEW_SWAP_DIRECTORIES_L1-1)) {
49 $p1 = sprintf ("$cn/%02X", $d1);
51 foreach $d2 (0..($NEW_SWAP_DIRECTORIES_L2-1)) {
52 $p2 = sprintf ("$p1/%02X", $d2);
58 $newlog = "$swaplog.1.1";
59 open (newlog
, ">$newlog") || die "$newlog: $!\n";
60 select(newlog
); $|=1; select(STDOUT
);
61 open (swaplog
) || die "$swaplog: $!\n";
65 ($file,$url,$expires,$timestamp,$size) = split;
66 @F = split('/', $file);
68 $oldpath = &old_fileno_to_path
($oldfileno);
69 unless (@S = stat($oldpath)) {
70 print "$oldpath: $!\n";
73 unless ($S[7] == $size) {
74 print "$oldpath: Wrong Size.\n";
77 $newpath = &new_fileno_to_path
($oldfileno);
78 next unless &my_link
($oldpath,$newpath);
79 printf newlog
"%08x %08x %08x %08x %9d %s\n",
93 $count files were linked to the new directories.
95 At this point you need to manually run these commands:
98 foreach $c (@cachedirs) {
99 print " /bin/mv $c $c.old; /bin/mv $c.new $c\n";
103 /bin/mv $swaplog $swaplog.old; /bin/mv $newlog $swaplog\n";
105 And then start up Squid version 1.1.
113 sub old_fileno_to_path
{
115 sprintf ("%s/%02d/%d",
116 $cachedirs[$fn % $ncache_dirs],
117 ($fn / $ncache_dirs) % $OLD_SWAP_DIRECTORIES,
121 sub new_fileno_to_path
{
123 sprintf ("%s.new/%02X/%02X/%08X",
124 $cachedirs[$fn % $ncache_dirs],
125 ($fn / $ncache_dirs) % $NEW_SWAP_DIRECTORIES_L1,
126 ($fn / $ncache_dirs) / $NEW_SWAP_DIRECTORIES_L1 % $NEW_SWAP_DIRECTORIES_L2,
132 print "Making $p...\n";
133 return if ($dry_run);
134 unless (mkdir ($p, 0755)) {
135 return 1 if ($! == $EEXIST);
143 return 1 if ($dry_run);
146 warn "$t: $!\n" unless ($rc);