A complex statement like this seems to work
find . -mtime +225 -exec sh -c 'echo "\n" && echo File = "{}"; bkf="/mount/backup/{}"; echo Backupfile = \""${bkf}"\" . ; test -f "$bkf" && echo do the touch && echo okok ; echo end' \;
where 225 is the days between now and the backup (somehow rounded, reference)
The find
's exec
is well described here
Edit:
If you have your Backup archived using tar/tar.gz, you do not need to extract all files, but can simply cd
to the backup and issue following command (reference: list tar contents) to get metadata of all files in the backup:
for f in *.tar.gz ; do echo $f; tar -v -t -f $f > "/tmp/contents_backup-20200401/$f.txt"; done
(dont know why the -z option was not needed even though the archive was compressed using gzip)
This data is in ASCII table format with space delimied. Unfortunately cut
cannot operate with variable spacing, but awk
can.
The follwing procedure works smoothly (except some ugly file names with dollar or apostroph signs or brackets). This can be partly fixed by using fgrep
instead of grep
but actually it is also find's output by {}
that is stripped when filename contains for instance a dollar sign or apostrophe.
navigate to the folder of the live system, then:
find * -type f -mtime +244 -exec sh -c 'echo "\n" && echo File = "{}"; lastmod=$(stat -c %y "{}" |cut -c-16); echo "LastMod TimeStamp = \""$lastmod"\"" ; dt=$(echo "$lastmod" | cut -c-10) && [ "$dt" = "2020-07-10" ] && ( echo "old file detected" ; timestamp=$(fgrep "{}" /tmp/contents_backup-20200401/backup-musik.tar.gz.txt | head -n1 | awk -F" " '"'"'{ print $4 " " $5 }'"'"' ); echo "Backup TimeStamp = \""${timestamp}"\"" . ; test -n "$timestamp" && echo "do the touch" && touch -d "$timestamp" "{}"; echo "ret=$?" && echo okok ) ; echo end' \;
whereby:
244
is the days from the backup till now (as a first filter)
2020-07-10
is the hardcoded date , only files with this date will be affected
/tmp/contents_backup-20200401/backup-musik.tar.gz.txt
is the file generated by the above mentioned command
What this command does:
- loop through files in live system
- check if they are affected by a wrong date issue (it is old and was this not altered after the backup, then you dont want to reset its timestamp)
- lookup in the backup listing and find the corresponding entry (this does not work for folders* unfortunately since many files would be found which are in the folder)
- using
awk
get the timestamp of the backuped file
- report about success
*) folder datetimes can be set using this command based on the latest file in that folder (actually this needs to be applied to all folders recursively)
stat -c %y . && touch -r "$(find -mindepth 1 -maxdepth 1 -printf '%T+=%p\n' | sort |tail -n 1 | cut -d= -f2-)" . && stat -c %y .
Edit2:
escaping (single apostrophe) using correct syntax is sometimes difficult.
Edit3:
This command can be executed in any subfolder which might lead to non-unique matches in the backup lookup, so this will be reported as well:
find * -type f -mtime +244 -exec sh -c 'echo "\n" && echo File = "{}"; lastmod=$(stat -c %y "{}" |cut -c-16); echo "LastMod TimeStamp = \""$lastmod"\"" ; dt=$(echo "$lastmod" | cut -c-10) && [ "$dt" = "2020-07-10" ] && ( echo "old file detected" ; filelist=$(fgrep "{}" /tmp/contents_backup-20200401/backup-dokumente.tar.gz.txt); filecount=$(echo "$filelist"|wc -l); echo "file count = $filecount"; [ "$filecount" -gt "1" ] && echo "multiple files found" ; timestamp=$(echo "$filelist" | head -n1 | awk -F" " '"'"'{ print $4 " " $5 }'"'"' ); echo "Backup TimeStamp = \""${timestamp}"\"" . ; [ $(echo -n "$timestamp" | wc -m) = 16 ] && echo "do the touch" && touch -d "$timestamp" "{}"; echo "ret=$?" && echo okok ) ; echo end' \;
find
) for older files (perhaps with the-mtime
directive) and touch the corresponding backup file (with something like-exec sh -c 'for file; do bkp=${file/#\/home/\/mount\/backup}; touch ...; done' _ "
)restic
orborgbackup
, not an tape archiving tool or file transfer utility.tar
to extract individual files from atar
archive, it's unclear what you do to reset themtime
timestamp (you don't show what command you use). GNUtar
extracts themtime
stored in thetar
archive and won't reset it unless you use-m
.