WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: patch for filetool.sh to "start fresh" before restoring  (Read 3448 times)

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
patch for filetool.sh to "start fresh" before restoring
« on: February 24, 2020, 07:49:11 AM »
curaga and juanito,

Some of my configuration directories restored from  mydata.tgz  quickly accumulate extraneous files while the system is running (~/.mozilla and ~/.thunderbird are notorious in this regard).

Because of how  tar  works, running  filetool.sh -r  does not get rid of the extraneous files. Therefore, if I want to restore my configuration directories to their pristine state (as found in mydata.tgz) after the system has been running for a while, I have to manually delete a bunch of directories and only then run  filetool.sh -r  . This is inconvenient.

Therefore, I created a patch for /usr/bin/filetool.sh (see attached) that adds a -z flag to delete ("zero out") all items listed in /opt/.filetool.lst. Now running  filetool.sh -zr  does exactly what I need.

I hope the patch is useful.

    [EDIT]: Patch removed. Safer patches are attached in later posts.  Rich
« Last Edit: February 24, 2020, 09:11:12 AM by Rich »

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #1 on: February 24, 2020, 07:58:15 AM »
Hi GNUser
You don't use a persistent  home  directory?

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #2 on: February 24, 2020, 07:59:06 AM »
No. My /opt is persistent, but not /home.
I dislike the accumulation of files whose function is unknown to me. Call me a clean freak ;D
« Last Edit: February 24, 2020, 08:02:03 AM by GNUser »

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #3 on: February 24, 2020, 08:02:02 AM »
Hi GNUser
You do know there is also an  /opt/.xfiletool.lst  for files and subdirectories you want to exclude from your backup.

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #4 on: February 24, 2020, 08:04:39 AM »
I know, Rich. Thank you.
I prefer to include only what I know I want (rather than exclude what I know I don't want). It keeps things as neat and tiny as possible.
« Last Edit: February 24, 2020, 08:12:22 AM by GNUser »

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #5 on: February 24, 2020, 08:36:05 AM »
Hi GNUser
So if I understand this patch correctly, if someone executes:
Code: [Select]
filetool.sh -zIt will read the list of all the files/directories they care about and then delete them.

If that's the case, I would strongly recommend against that patch, at least in its current state. It's too easy for someone to shoot
themselves in the foot.

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #6 on: February 24, 2020, 08:41:32 AM »
...will read the list of all the files/directories they care about and then delete them.
That's correct. I guess it is a dangerous patch as currently written.

The operation is not dangerous when -z is combined with -r
I'll rework it and submit a safer patch.

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #7 on: February 24, 2020, 08:52:02 AM »
Here you go. Now -z can only be used if combined with -r

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #8 on: February 24, 2020, 08:55:07 AM »
Patch with better placement of the safety check is attached.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #9 on: February 24, 2020, 09:08:05 AM »
Hi GNUser
Since it tests for an illegal condition, I would change this:
Code: [Select]
+if [ "$ZERO" ] && [ ! "$RESTORE" ]; then
+  echo "-z should only be used with -r"
+fi
+
To that:
Code: [Select]
+if [ "$ZERO" ] && [ ! "$RESTORE" ]; then
+  echo "-z should only be used with -r"
+  exit 3
+fi
+

I will remove the patch you attached in your original post.

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #10 on: February 24, 2020, 09:12:51 AM »
Since it tests for an illegal condition...
Good idea. Updated patch attached.

I will remove the patch you attached in your original post.
Thank you. Best not to have the dangerous version of the patch lying around.

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #11 on: February 24, 2020, 09:20:45 AM »
Maybe too few users would have any use for the  -z  option? If so, feel free to ignore the patch.

It would be easy enough for the few users who might need this to use a shell script (cleanup followed by filetool.sh -r) instead.
« Last Edit: February 24, 2020, 09:30:27 AM by GNUser »

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #12 on: February 24, 2020, 09:32:31 AM »
Hi GNUser
Maybe too few users would have any use for the  -z  option? If so, feel free to ignore the patch. ...
I was going to mention that your patch may not get accepted as being too specialized. Using  restore  to do a file system cleanup
on a running system is a new one on me.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10957
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #13 on: February 24, 2020, 09:34:59 AM »
This is the first time this has come up, and I believe a safer/more obvious way to get the same result is to reboot. So right now I'm not inclined to add the patch.
The only barriers that can stop you are the ones you create yourself.

Offline GNUser

  • Hero Member
  • *****
  • Posts: 1343
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #14 on: February 24, 2020, 09:39:56 AM »
I figured the patch might be rejected in favor of achieving the same thing (yes, in a safer/more obvious way) with a reboot. Fair enough.

You guys do a great job at keeping TCL tiny and beautiful. Thank you :)
« Last Edit: February 24, 2020, 09:43:01 AM by GNUser »