WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
patch for filetool.sh to "start fresh" before restoring
« on: February 24, 2020, 10: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, 12:11:12 PM by Rich »

Offline Rich

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

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #2 on: February 24, 2020, 10: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, 11:02:03 AM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11703
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #3 on: February 24, 2020, 11: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

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #4 on: February 24, 2020, 11: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, 11:12:22 AM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11703
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #5 on: February 24, 2020, 11: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

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #6 on: February 24, 2020, 11: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

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

Offline GNUser

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

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11703
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #9 on: February 24, 2020, 12:08:05 PM »
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

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #10 on: February 24, 2020, 12:12:51 PM »
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

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #11 on: February 24, 2020, 12:20:45 PM »
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, 12:30:27 PM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11703
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #12 on: February 24, 2020, 12:32:31 PM »
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: 11049
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #13 on: February 24, 2020, 12:34:59 PM »
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

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: patch for filetool.sh to "start fresh" before restoring
« Reply #14 on: February 24, 2020, 12:39:56 PM »
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, 12:43:01 PM by GNUser »