commit 03dda87ba923461fb727b31d800f3907ba18dacd Author: Thomas Nikolajsen Date: Sat Apr 6 11:57:05 2013 +0200 backupworld build(7) feature update Make backupworld-auto build(7) feature optional and fix some problems: * add BACKUPWORLD_AUTO; if set backupworld-auto will do backup; default unset * support NFS MAKEOBJDIRPREFIX (e.g. /usr/obj) (as described in Makefile.inc1) ** don't fail use tar(1) to store chflags(2) flags info (`cp -p' fails as NFS doesn't support chflags(2) flags) ** make auto-backup per host restore from other host could be disaster we don't have system UUID; use hostname * make auto-backup per TARGET_ARCH restore from other ARCH could be disaster * make auto-backup per DESTDIR restore from other DESTDIR could be disaster * don't fail for initial installworld check if anything to backup diff --git a/Makefile b/Makefile index 16bd679..fb064d6 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,14 @@ # 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 /lib /libexec +# to manual backup dir. +# backupworld-auto-clean - Delete backup from auto-backup dir. +# backupworld-auto-clean-all - Delete all backups from auto-backup dir. +# backupworld-clean - Delete backup from 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. # # This makefile is simple by design. The DragonFly make automatically reads # /usr/share/mk/sys.mk unless the -m argument is specified on the diff --git a/Makefile.inc1 b/Makefile.inc1 index dc172b5..7562f7a 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 # 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 /lib /libexec to manual backup dir +# backupworld-auto-clean - delete backup from auto-backup dir +# backupworld-auto-clean-all - delete all backups from auto-backup dir +# backupworld-clean - delete backup from manual backup dir +# restoreworld- installs binaries from manual backup dir to world +# restoreworld-auto - installs binaries from auto-backup dir to world # # Standard targets (not defined here) are documented in the makefiles in # /usr/share/mk. These include: @@ -125,11 +129,6 @@ WORLD_CCVER?= gcc47 WORLD_LDVER?= ld.bfd WORLD_BINUTILSVER?= binutils222 -# Set the backup parameters if they are not already defined -# -WORLD_BACKUP?= /var/backups/world_backup -AUTO_BACKUP= ${OBJTREE}/world_backup - # temporary until everybody has converted to x86_64 .if ${MACHINE_ARCH} == "amd64" MACHINE_ARCH= x86_64 @@ -178,6 +177,13 @@ TARGET_PLATFORM= pc64 .endif .endif +# Set the backup parameters if they are not already defined +# +WORLD_BACKUP?= /var/backups/world_backup +HOSTNAME!= hostname +AUTO_BACKUP_BASE= ${OBJTREE}/world_backup +AUTO_BACKUP= ${AUTO_BACKUP_BASE}/${HOSTNAME}/${TARGET_ARCH}/${DESTDIR} + THREAD_LIB?= thread_xu .if ${THREAD_LIB} == "c_r" .if defined(NO_LIBC_R) @@ -421,7 +427,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 +1058,58 @@ xmake: xmakeenv: @echo '${XMAKEENV} /bin/sh' -backupworld: +backupworld: backupworld-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(BACKUPWORLD_AUTO) + 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 +backupworld-auto-clean: + rm -f ${AUTO_BACKUP}/binaries.tar.gz + +backupworld-auto-clean-all: + rm -rf ${AUTO_BACKUP_BASE} + +backupworld-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..222264c 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 # +# To backup old world binaries as part of installworld +#BACKUPWORLD_AUTO= 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..1865e70 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 6, 2013 .Dt MAKE.CONF 5 .Os .Sh NAME @@ -212,17 +212,27 @@ To have components compared before doing the install, use .Bd -literal -offset indent INSTALL="install -C" .Ed +.It Va BACKUPWORLD_AUTO +.Pq Vt str +Enable backup of old world binaries as part 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 /var/backups/world_backup . +.Dq backupworld +.Xr make 1 +target. +The default value is +.Dq Pa /var/backups/world_backup . .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..705b268 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 6, 2013 .Dt BUILD 7 .Os .Sh NAME @@ -132,6 +131,32 @@ just installed. Build user commands, no libraries or include files. .It Cm installmost Install user commands, no libraries or include files. +.It Cm backupworld +Backup binaries from installed world to location specified in +.Ev WORLD_BACKUP . +.It Cm backupworld-auto +Backup binaries from installed world to auto-backup directory. +This is only done if +.Ev BACKUPWORLD_AUTO +is defined. +Auto-backup directory is: +.Ev MAKEOBJDIRPREFIX Ns Pa /world_binaries/ Ns Ao Ar hostname Ac Ns / Ns Ev TARGET_ARCH Ns / Ns Ev DESTDIR . +This is executed as initial part of +.Cm installworld . +.It Cm backupworld-auto-clean +Delete backup from auto-backup directory. +See +.Cm backupworld-auto . +.It Cm backupworld-auto-clean-all +Delete all backups from auto-backup base directory: +.Ev MAKEOBJDIRPREFIX Ns Pa /world_binaries . +.It Cm restoreworld +Restore binaries to installed world from location specified in +.Ev WORLD_BACKUP . +.It Cm restoreworld-auto +Restore binaries to installed world from auto-backup directory. +See +.Cm backupworld-auto . .El .Sh ENVIRONMENT .Bl -tag -width ".Ev MAKEOBJDIRPREFIX" @@ -208,6 +233,9 @@ 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 (the default is +.Pa /var/backups/world_backup ) . .El .Sh FILES .Bl -tag -width ".Pa /usr/src/Makefile_upgrade.inc" -compact