From 61443441615c49aa6d0ba3d401e7335014e372b4 Mon Sep 17 00:00:00 2001 From: John Marino Date: Sun, 17 Feb 2013 21:14:48 +0100 Subject: [PATCH] build: implement automatic world backups The directives DAYS_BACKUP and NO_BACKUP have been removed. The "backupworld" target will save important directories to the WORLD_BACKUP directory just as before, and it is restored with the "restoreworld" target. Additionally, every time the "installworld" target is executed, the same directories will be automatically backed up at the location of ${MAKEOBJDIRPREFIX}/world_backup . These directories could be restored with the new make target "restoreworld-auto". The WORLD_BACKUP location default is now /var/backups/world_backup . The directory /usr/lib has been added to the backup list. The more useless errors seen with a broken world have been removed, these came in with bmake. --- Makefile | 2 +- Makefile.inc1 | 71 ++++++++++++++++++++++++++------------ share/man/man5/make.conf.5 | 14 +------- 3 files changed, 50 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 0c9a461951..16bd679319 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ TGTS= all all-man buildkernel quickkernel nativekernel \ hierarchy install installcheck installkernel \ reinstallkernel installmost installworld libraries lint maninstall \ manlint mk most obj objlink regress rerelease tags \ - backupworld restoreworld \ + backupworld restoreworld restoreworld-auto \ _obj _includes _libraries _depend _worldtmp \ _bootstrap-tools _build-tools _cross-tools diff --git a/Makefile.inc1 b/Makefile.inc1 index 37b8ae07d2..07d1f57f21 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -127,17 +127,8 @@ WORLD_BINUTILSVER?= binutils222 # Set the backup parameters if they are not already defined # -WORLD_BACKUP?= /var/backups/world_binaries -DAYS_BACKUP?= 28 -.if exists(${WORLD_BACKUP}/lastbackup) -BK_REFERENCE!= date +'%s' -BK_EXPIRES!= expr ${DAYS_BACKUP} \* 86400 + `cat ${WORLD_BACKUP}/lastbackup` -. if ${BK_REFERENCE} > ${BK_EXPIRES} -BACKUP_EXPIRED= yes -. endif -.else -NEVER_BACKED_UP= yes -.endif +WORLD_BACKUP?= /var/backups/world_backup +AUTO_BACKUP= ${OBJTREE}/world_backup # temporary until everybody has converted to x86_64 .if ${MACHINE_ARCH} == "amd64" @@ -462,6 +453,7 @@ crossworld: _worldtmp _bootstrap-tools _obj _build-tools _cross-tools .ORDER: ${WMAKE_TGTS} .ORDER: _obj _includes .ORDER: _mtreetmp _obj +.ORDER: installcheck backupworld-auto # # installcheck @@ -484,7 +476,7 @@ installcheck: # # Installs everything compiled by a 'buildworld'. # -installworld: installcheck +installworld: installcheck backupworld-auto cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//} ${INSTALL} -o root -g wheel -m 644 ${.CURDIR}/Makefile_upgrade.inc ${DESTDIR}/etc/upgrade/ @@ -1066,22 +1058,35 @@ backupworld: @rm -rf ${WORLD_BACKUP}/sbin ${WORLD_BACKUP}/bin \ ${WORLD_BACKUP}/usr.sbin ${WORLD_BACKUP}/usr.bin \ ${WORLD_BACKUP}/usr.libexec - cp -a /sbin ${WORLD_BACKUP}/sbin cp -a /bin ${WORLD_BACKUP}/bin - cp -a /usr/sbin ${WORLD_BACKUP}/usr.sbin + cp -a /sbin ${WORLD_BACKUP}/sbin cp -a /usr/bin ${WORLD_BACKUP}/usr.bin + cp -a /usr/lib ${WORLD_BACKUP}/usr.lib + cp -a /usr/sbin ${WORLD_BACKUP}/usr.sbin cp -a /usr/libexec ${WORLD_BACKUP}/usr.libexec - @date +'%s' > ${WORLD_BACKUP}/lastbackup + +backupworld-auto: + @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 -a /bin ${AUTO_BACKUP}/bin + cp -a /sbin ${AUTO_BACKUP}/sbin + cp -a /usr/bin ${AUTO_BACKUP}/usr.bin + cp -a /usr/lib ${AUTO_BACKUP}/usr.lib + cp -a /usr/sbin ${AUTO_BACKUP}/usr.sbin + cp -a /usr/libexec ${AUTO_BACKUP}/usr.libexec restoreworld: .if !(exists(${WORLD_BACKUP}/sbin) && exists(${WORLD_BACKUP}/bin) && \ exists(${WORLD_BACKUP}/usr.sbin) && exists(${WORLD_BACKUP}/usr.bin) && \ - exists(${WORLD_BACKUP}/usr.libexec)) + exists(${WORLD_BACKUP}/usr.lib) && exists(${WORLD_BACKUP}/usr.libexec)) @echo "There does not seem to be a valid archive present." .else - @echo "Restoring system binaries from backup archive..." + @echo "Restoring system binaries from manual backup archive..." @rm -f /tmp/rs.tmp -.for BX in sbin bin usr.sbin usr.bin usr.libexec +.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 \; @@ -1097,21 +1102,41 @@ restoreworld: @echo " /usr/libexec/ld-elf.so.2" .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)) + @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" +.endif + # Take advantage of bmake error response # MAKE_PRINT_VAR_ON_ERROR= \ .CURDIR \ .OBJDIR \ - .MAKE \ - MAKE_VERSION \ LD_LIBRARY_PATH \ MACHINE_ARCH \ MACHINE \ MAKEFILE \ .TARGETS \ .ERROR_TARGET \ - .ERROR_META_FILE \ - .MAKE.LEVEL \ - .MAKE.MODE + .MAKE.LEVEL .include diff --git a/share/man/man5/make.conf.5 b/share/man/man5/make.conf.5 index 22f0e37d8d..3cf0089ae3 100644 --- a/share/man/man5/make.conf.5 +++ b/share/man/man5/make.conf.5 @@ -217,19 +217,7 @@ INSTALL="install -C" defines where system binaries will be backed up for the .Dq make backupworld target. The default value is -.Dq /var/backups/world_binaries . -.It Va DAYS_BACKUP -.Pq Vt int -If the last world backup is older than the number of days -defined here, the -.Dq make installworld -will fail with an appropriate message. -.Dq 28 -is the default value. -.It Va NO_BACKUP -.Pq Vt bool -Set this to skip the existence and currency checks for world -binary backups. +.Dq /var/backups/world_backup . .It Va LOCAL_DIRS .Pq Vt str List any directories that should be entered when running make -- 2.41.0