From b40cc61dcd8c403ddda69a8e400e226b7707e2bf Mon Sep 17 00:00:00 2001 From: John Marino Date: Tue, 16 Apr 2013 02:42:13 +0200 Subject: [PATCH] Makefile.inc: Rework automatic backup (bug 2527) There were three main problems with the recently added backup feature: 1. It didn't work over NFS 2. It didn't work when a non-root built world the second time 3. It didn't use DESTDIR which had potential to conflict backups It also previously featured "NO_BACKUP" which turned off the automatic backup feature. To fix the #2 problem, the install timestamp has been removed, so to avoid unwanted backups for multiple installworlds after one buildworld, the user needs to pass NO_BACKUP in the command line. This patch was contributed by Thomas Nikolajsen with minor modifications added by John Marino. http://bugs.dragonflybsd.org/issues/2527 --- Makefile | 8 +++ Makefile.inc1 | 103 +++++++++++++++++--------------------------- etc/defaults/make.conf | 3 + share/man/man5/make.conf.5 | 31 +++++++++++--- share/man/man7/build.7 | 32 ++++++++++++- 5 files changed, 105 insertions(+), 72 deletions(-) diff --git a/Makefile b/Makefile index 16bd679..4ce85c6 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,13 @@ # of the system for DragonFly. ex. two compilers # most - Build user commands, no libraries or include files. # installmost - Install user commands, no libraries or include files. +# backupworld - Copies /bin /sbin /usr/bin /usr/sbin /usr/lib +# /usr/libexec to manual backup dir. +# restoreworld - Installs binaries from manual backup dir to world. +# restoreworld-auto - Installs binaries from auto-backup dir to world; +# installworld target makes backup to auto-backup dir. +# backup-auto-clean - Delete backup from auto-backup dir. +# backup-clean - Delete backup from manual backup dir. # # This makefile is simple by design. The DragonFly make automatically reads # /usr/share/mk/sys.mk unless the -m argument is specified on the @@ -76,6 +83,7 @@ TGTS= all all-man buildkernel quickkernel nativekernel \ reinstallkernel installmost installworld libraries lint maninstall \ manlint mk most obj objlink regress rerelease tags \ backupworld restoreworld restoreworld-auto \ + backup-clean backup-auto-clean \ _obj _includes _libraries _depend _worldtmp \ _bootstrap-tools _build-tools _cross-tools diff --git a/Makefile.inc1 b/Makefile.inc1 index dc172b5..6586e46 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -10,10 +10,14 @@ # realquickworld - skip the glue and depend stages and just build the meat # crossworld - only build the glue (particularly the cross-build environment) # installworld- install everything built by "buildworld" -# backupworld - copies /bin /sbin /usr/bin /usr/sbin /libexec to backup dir -# restoreworld- installs binaries from backup dir to world +# backupworld - copies /bin /sbin /usr/bin /usr/sbin /usr/lib /usr/libexec +# to manual backup dir +# restoreworld- installs binaries from manual backup dir to world +# restoreworld-auto - installs binaries from auto-backup dir to world # most - build user commands, no libraries or include files # installmost - install user commands, no libraries or include files +# backup-clean - delete backup from manual backup dir +# backup-auto-clean - delete backup from auto-backup dir # # Standard targets (not defined here) are documented in the makefiles in # /usr/share/mk. These include: @@ -128,7 +132,7 @@ WORLD_BINUTILSVER?= binutils222 # Set the backup parameters if they are not already defined # WORLD_BACKUP?= /var/backups/world_backup -AUTO_BACKUP= ${OBJTREE}/world_backup +AUTO_BACKUP?= ${OBJTREE}/world_backup/${DESTDIR} # temporary until everybody has converted to x86_64 .if ${MACHINE_ARCH} == "amd64" @@ -421,7 +425,6 @@ everything: @echo ">>> stage 4d: building everything.." @echo "--------------------------------------------------------------" cd ${.CURDIR}; ${WMAKE} all - @rm -f ${AUTO_BACKUP}/installstamp # note: buildworld no longer depends on _cleanobj because we rm -rf the # entire object tree and built the bootstrap tools in a different location. @@ -1053,81 +1056,55 @@ xmake: xmakeenv: @echo '${XMAKEENV} /bin/sh' -backupworld: +backupworld: backup-clean @mkdir -p ${WORLD_BACKUP} - @chflags -R noschg ${WORLD_BACKUP} - @rm -rf ${WORLD_BACKUP}/sbin ${WORLD_BACKUP}/bin \ - ${WORLD_BACKUP}/usr.sbin ${WORLD_BACKUP}/usr.bin \ - ${WORLD_BACKUP}/usr.libexec - cp -RpP /bin ${WORLD_BACKUP}/bin - cp -RpP /sbin ${WORLD_BACKUP}/sbin - cp -RpP /usr/bin ${WORLD_BACKUP}/usr.bin - cp -RpP /usr/lib ${WORLD_BACKUP}/usr.lib - cp -RpP /usr/sbin ${WORLD_BACKUP}/usr.sbin - cp -RpP /usr/libexec ${WORLD_BACKUP}/usr.libexec +.if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \ + exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \ + exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec)) + tar -czf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \ + --options gzip:compression-level=1 \ + sbin bin usr/sbin usr/bin usr/lib usr/libexec +.endif backupworld-auto: -.if !exists(${AUTO_BACKUP}/installstamp) +.if !defined(NO_BACKUP) + rm -f ${AUTO_BACKUP}/binaries.tar.gz @mkdir -p ${AUTO_BACKUP} - @chflags -R noschg ${AUTO_BACKUP} - @rm -rf ${AUTO_BACKUP}/sbin ${AUTO_BACKUP}/bin \ - ${AUTO_BACKUP}/usr.sbin ${AUTO_BACKUP}/usr.bin \ - ${AUTO_BACKUP}/usr.libexec - cp -RpP /bin ${AUTO_BACKUP}/bin - cp -RpP /sbin ${AUTO_BACKUP}/sbin - cp -RpP /usr/bin ${AUTO_BACKUP}/usr.bin - cp -RpP /usr/lib ${AUTO_BACKUP}/usr.lib - cp -RpP /usr/sbin ${AUTO_BACKUP}/usr.sbin - cp -RpP /usr/libexec ${AUTO_BACKUP}/usr.libexec - @date '+%Y-%m-%d %H:%M:%S' > ${AUTO_BACKUP}/installstamp +.if (exists(${DESTDIR}/sbin) && exists(${DESTDIR}/bin) && \ + exists(${DESTDIR}/usr/sbin) && exists(${DESTDIR}/usr/bin) && \ + exists(${DESTDIR}/usr/lib) && exists(${DESTDIR}/usr/libexec)) + tar -czf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ \ + --options gzip:compression-level=1 \ + sbin bin usr/sbin usr/bin usr/lib usr/libexec +.endif .endif +backup-auto-clean: + rm -f ${AUTO_BACKUP}/binaries.tar.gz + +backup-clean: + rm -f ${WORLD_BACKUP}/binaries.tar.gz + restoreworld: -.if !(exists(${WORLD_BACKUP}/sbin) && exists(${WORLD_BACKUP}/bin) && \ - exists(${WORLD_BACKUP}/usr.sbin) && exists(${WORLD_BACKUP}/usr.bin) && \ - exists(${WORLD_BACKUP}/usr.lib) && exists(${WORLD_BACKUP}/usr.libexec)) +.if !exists(${WORLD_BACKUP}/binaries.tar.gz) @echo "There does not seem to be a valid archive present." .else @echo "Restoring system binaries from manual backup archive..." - @rm -f /tmp/rs.tmp -.for BX in sbin bin usr.sbin usr.bin usr.lib usr.libexec - @chflags -R noschg /${BX:S/./\//} - @cd ${WORLD_BACKUP}/${BX} && find * -type f -perm +700 -exec \ - echo cp ${WORLD_BACKUP}/${BX}/{} /${BX:S/./\//}/{} >> /tmp/rs.tmp \; -.endfor - @grep -Ev ' (/bin/sh|/bin/cp|/sbin/init.bak|/usr/bin/make|/usr/libexec/ld-elf.so.2|/usr/libexec/ld-elf.so.2.old)$$' \ - /tmp/rs.tmp > /tmp/restore.script - @/bin/sh /tmp/restore.script - @rm /tmp/rs.tmp /tmp/restore.script - @echo "These files were not restored from ${WORLD_BACKUP}:" - @echo " /bin/cp" - @echo " /bin/sh" - @echo " /usr/bin/make" - @echo " /usr/libexec/ld-elf.so.2" + @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \ + ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \ + ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec + tar -xzf ${WORLD_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ .endif restoreworld-auto: -.if !(exists(${AUTO_BACKUP}/sbin) && exists(${AUTO_BACKUP}/bin) && \ - exists(${AUTO_BACKUP}/usr.sbin) && exists(${AUTO_BACKUP}/usr.bin) && \ - exists(${AUTO_BACKUP}/usr.lib) && exists(${AUTO_BACKUP}/usr.libexec)) +.if !exists(${AUTO_BACKUP}/binaries.tar.gz) @echo "There does not seem to be a valid archive present." .else @echo "Restoring system binaries from auto-backup archive..." - @rm -f /tmp/rs.tmp -.for BX in sbin bin usr.sbin usr.bin usr.lib usr.libexec - @chflags -R noschg /${BX:S/./\//} - @cd ${AUTO_BACKUP}/${BX} && find * -type f -perm +700 -exec \ - echo cp ${AUTO_BACKUP}/${BX}/{} /${BX:S/./\//}/{} >> /tmp/rs.tmp \; -.endfor - @grep -Ev ' (/bin/sh|/bin/cp|/sbin/init.bak|/usr/bin/make|/usr/libexec/ld-elf.so.2|/usr/libexec/ld-elf.so.2.old)$$' \ - /tmp/rs.tmp > /tmp/restore.script - @/bin/sh /tmp/restore.script - @rm /tmp/rs.tmp /tmp/restore.script - @echo "These files were not restored from ${AUTO_BACKUP}:" - @echo " /bin/cp" - @echo " /bin/sh" - @echo " /usr/bin/make" - @echo " /usr/libexec/ld-elf.so.2" + @chflags -R noschg ${DESTDIR}/sbin ${DESTDIR}/bin \ + ${DESTDIR}/usr/sbin ${DESTDIR}/usr/bin \ + ${DESTDIR}/usr/lib ${DESTDIR}/usr/libexec + tar -xzf ${AUTO_BACKUP}/binaries.tar.gz -C ${DESTDIR}/ .endif # Take advantage of bmake error response diff --git a/etc/defaults/make.conf b/etc/defaults/make.conf index fc0d1c0..f3d9ce1 100644 --- a/etc/defaults/make.conf +++ b/etc/defaults/make.conf @@ -81,6 +81,9 @@ BDECFLAGS= -W -Wall -ansi -pedantic -Wbad-function-cast -Wcast-align \ # Compare before install #INSTALL=install -C # +# Inhibit the automatic backup during installworld +#NO_BACKUP= true +# # To build ppp with normal permissions #PPP_NOSUID= true # diff --git a/share/man/man5/make.conf.5 b/share/man/man5/make.conf.5 index 3cf0089..1e0bd7c 100644 --- a/share/man/man5/make.conf.5 +++ b/share/man/man5/make.conf.5 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD: src/share/man/man5/make.conf.5,v 1.12.2.30 2003/05/18 17:05:55 brueffer Exp $ .\" -.Dd February 17, 2013 +.Dd April 16, 2013 .Dt MAKE.CONF 5 .Os .Sh NAME @@ -212,17 +212,36 @@ To have components compared before doing the install, use .Bd -literal -offset indent INSTALL="install -C" .Ed +.It Va NO_BACKUP +.Pq Vt str +Inhibit automatic backup of world binaries as port of +.Dq installworld +.Xr make 1 +target. +Default is unset. .It Va WORLD_BACKUP .Pq Vt str defines where system binaries will be backed up for the -.Dq make backupworld -target. The default value is +.Dq backupworld +.Xr make 1 +target. +The default is .Dq /var/backups/world_backup . +.It Va AUTO_BACKUP +.Pq Vt str +defines where system binaries will be backed up automatically +as part of the +.Dq installworld +.Xr make 1 +target. +The default is +.Dq Ev MAKEOBJDIRPREFIX Ns /world_binaries/ Ns Ev DESTDIR . .It Va LOCAL_DIRS .Pq Vt str -List any directories that should be entered when running make -.Pa /usr/src -in this variable. +List of directories that should be entered when running +.Xr make 1 +in +.Pa /usr/src . .It Va MAKE_SHELL .Pq Vt str Controls the shell used internally by diff --git a/share/man/man7/build.7 b/share/man/man7/build.7 index 416ece0..725512e 100644 --- a/share/man/man7/build.7 +++ b/share/man/man7/build.7 @@ -23,9 +23,8 @@ .\" SUCH DAMAGE. .\" .\" $FreeBSD: src/share/man/man7/build.7,v 1.19.2.1 2002/03/18 08:33:02 murray Exp $ -.\" $DragonFly: src/share/man/man7/build.7,v 1.18 2008/11/14 15:04:42 swildner Exp $ .\" -.Dd April 12, 2009 +.Dd April 16, 2013 .Dt BUILD 7 .Os .Sh NAME @@ -77,7 +76,7 @@ Installs the results of the build for this directory. The other .Pa /usr/src make targets are: -.Bl -tag -width ".Cm reinstallkernel" +.Bl -tag -width ".Cm backup-auto-clean" .It Cm buildworld Rebuild everything but the kernel. .It Cm quickworld @@ -132,6 +131,23 @@ just installed. Build user commands, no libraries or include files. .It Cm installmost Install user commands, no libraries or include files. +.It Cm backupworld +Manually archive binaries from installed world to location specified by +.Ev WORLD_BACKUP . +.It Cm backup-clean +Delete archive created by +.Cm backupworld . +.It Cm backup-auto-clean +Delete archive created automatically during +.Cm installworld . +.It Cm restoreworld +Restore binaries from archive created by +.Cm backupworld . +.It Cm restoreworld-auto +Restore binaries from archive created automatically during +.Cm installworld . +The archive location is specified by +.Ev AUTO_BACKUP . .El .Sh ENVIRONMENT .Bl -tag -width ".Ev MAKEOBJDIRPREFIX" @@ -208,6 +224,16 @@ under the directory specified by .Ev DESTKERNDIR . This overrides the effect of .Ev DESTLABEL . +.It Ev WORLD_BACKUP +Directory for manual backup of binaries of installed world (default: +.Pa /var/backups/world_backup ) . +.It Ev AUTO_BACKUP +Directory for automatic backup of binaries of installed world (default: +.Ev MAKEOBJDIRPREFIX Ns /world_binaries/ Ns Ev DESTDIR ) . +.It Ev NO_BACKUP +When defined, the automatic backup feature of +.Cm installworld +is inhibited. .El .Sh FILES .Bl -tag -width ".Pa /usr/src/Makefile_upgrade.inc" -compact -- 1.7.6.3