WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [ Solved ] Having trouble with Reboot and Backup  (Read 7050 times)

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
[ Solved ] Having trouble with Reboot and Backup
« on: April 05, 2017, 11:55:11 AM »
I guess my problem is I cannot find info on what order things occur during the "Reboot with Backup" option from the exit menu.

I have some files in a temporary location while TCL is running. When the Reboot/Backup is initiated I would like to delete the last saved set of files and replace them with the newest set of files from the temporary location. I want the new set of files to then be backed up when the Reboot/Backup is initiated.

The files are stored in /home/tc/searchfiles because it is automatically backed up with the home directory.

The newest files are in /tmp/csvfiles.

Currently I have edited the beginning of shutdown.sh to look like this:
Code: [Select]
#!/bin/busybox ash
. /etc/init.d/tc-functions
useBusybox
# put user shutdown commands here
rm -rf /home/tc/searchfiles/*
cp -rf /tmp/csvfiles/* /home/tc/searchfiles/
# If no backup of home was done then loop through valid users to clean up.

I didn't mess with the rest of the file because the comments there indicated exactly where to put user shutdown commands.
However, with my current configuration I keep getting the last old set of files. It is almost as if I am making my deletions and subsequent copies AFTER the backup has already happened.

I believe this to be the case because I have also altered the bootlocal.sh to recreate the temporary directory and repopulate it with the files saved in the last backup. It looks like this:
Code: [Select]
# put other system startup commands here
mkdir -m 777 /tmp/csvfiles
cp /home/tc/searchfiles/* /tmp/csvfiles/

When the Reboot/Backup completes I get the /tmp/csvfiles folder back and it is populated with an old set of files and not the ones that were most recent.

So do you think that is what is going on? If so, how do get ahead of the backup so my updated files get into the backup?
Again, this just feels like I am not understanding the order in which stuff happens.

Also, is there a command line command I can use to perform the Reboot with Backup like the UI does?

BKM
« Last Edit: April 06, 2017, 04:29:04 PM by gerald_clark »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11213
Re: Having trouble with Reboot and Backup
« Reply #1 on: April 05, 2017, 12:09:26 PM »
Hi bkm
This issue has come up at least once before. Here is one thread that addresses it:
http://forum.tinycorelinux.net/index.php/topic,17667.msg105997.html#msg105997

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Having trouble with Reboot and Backup
« Reply #2 on: April 05, 2017, 12:47:15 PM »
Ok, not a very clean solution, but it looks like I can do it.

One question about it though, you told the user to use sudo in the new script they write. I thought anything run from /usr/bin/ would be run as root. Is that wrong? Is sudo really needed?

Also, is there a command line command that will perform the Reboot/Backup, or do I need to make a script for that as well. If I need to write a script for it, where can I find syntax info for the backup part of it?

Thanks,

BKM

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Having trouble with Reboot and Backup
« Reply #3 on: April 05, 2017, 01:07:22 PM »
The directory  /usr/bin  is owned by root, so you need  sudo  to modify (i.e.  mv  and edit) anything inside.
Nothing will run as root, except when run by root or with  sudo .
To only perform a backup, run
Code: [Select]
filetool.sh -b
Download a copy and keep it handy: Core book ;)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11213
Re: Having trouble with Reboot and Backup
« Reply #4 on: April 05, 2017, 01:38:53 PM »
Hi bkm
Assuming you are following the basic blueprint I presented here:
http://forum.tinycorelinux.net/index.php/topic,17667.msg106022.html#msg106022
it could look something like this:
Code: [Select]
#!/bin/sh

# This script replaced  /usr/bin/exittc  which was renamed to  /usr/bin/exittc.real  so
# that these commands are run first.

# Delete old files
rm -rf /home/tc/searchfiles/*
# Save the most recent files
cp -rf /tmp/csvfiles/* /home/tc/searchfiles/
# Run the backup
filetool.sh -b

exittc.real


Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Having trouble with Reboot and Backup
« Reply #5 on: April 05, 2017, 01:40:32 PM »
Thanks Misalf. I will build a script for the function.

I am still having trouble getting anything to work ahead of the backup. I followed Rich's instructions to mv the exittc file to another name and create a script called exittc in it's place. I even remembered to run chmod on it to make it executable. I placed all the right things in the .filetool.lst to save them and then reloaded my test files.

I used the GUI exit menu to run the Reboot with Backup and again the older files are retained as if they were never deleted.

Here is my exittc script:
Code: [Select]
#!/bin/sh

# This script replaced /usr/bin/exittc which was
# renamed to /usr/bin/exittc.orig so the commands
# in this script run first.

# First delete the files left from the last backup

rm -rf /home/tc/searchfiles/*

# Then copy the most recent files from the temporary
# location to the location that gets backed up

cp -rf /tmp/csvfiles/* /home/tc/searchfiles/

# Finally we start the original exittc process

/usr/bin/exittc.orig


Either the exittc no longer works the way it did a few years ago, or my rm command is broken. If I run the rm command from the bash prompt it works fine, so now I am lost again.  ???

BKM

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Having trouble with Reboot and Backup
« Reply #6 on: April 05, 2017, 01:42:42 PM »
Rich

Looks like we posted at the same time and our scripts look almost identical.

But I see in yours the backup is run at the end. That was not in the post you referred to earlier. Is that now needed to make this work?

BKM
« Last Edit: April 05, 2017, 01:51:36 PM by bkm »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11213
Re: Having trouble with Reboot and Backup
« Reply #7 on: April 05, 2017, 01:56:28 PM »
Hi bkm
But I see in yours the backup is run at the end. That was not in the post you referred to earlier. Is that now needed to make this work?
Well yes, that was the problem in the first place. The backup was being run before the files were moved instead of after.

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Having trouble with Reboot and Backup
« Reply #8 on: April 05, 2017, 02:36:02 PM »
 >:( Now I am lost again.

Here is my latest update to the script:
Code: [Select]
#!/bin/sh

# This script replaced /usr/bin/exittc which was
# renamed to /usr/bin/exittc.orig so the commands
# in this script run first.

# First delete the files left from the last backup

rm -rf /home/tc/searchfiles/*

# Then copy the most recent files from the temporary
# location to the location that gets backed up

cp -rf /tmp/csvfiles/* /home/tc/searchfiles/

# Now run the backup function to save the file moves

/usr/bin/filetool.sh -b

# Finally we start the original exittc process

/usr/bin/exittc.orig

# End of script

After editing it each time I also run the chmod 770 to make it executable just in case my edits affected the permissions.

For each test I do the following:

- I load 2 files into the /home/tc/searchfiles   (TempOutput1.csv and TempOutput2.csv)
- Next I create a temp folder to store the new files with>    mkdir  -m 777 /tmp/csvfiles
- Then I load 2 different files into /tmp/csvfiles    (List1.csv and List2.csv)

With everything setup, I go to the TCL GUI and select the Exit Icon then the Reboot with Backup option and I wait for the system to reboot. When I then go check the /home/tc/searchfiles directory is till has the old files in there (TempOutput1.csv and TempOutput2.csv) Of course the /tmp/csvfiles no longer exists after the reboot but the files that were there were not saved.

For the life of me I cannot see where this goes off the rails.

I have even tried it with sudo before the backup and the exittc commands. Same result.

Any ideas?

BKM
« Last Edit: April 05, 2017, 02:46:23 PM by bkm »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Having trouble with Reboot and Backup
« Reply #9 on: April 05, 2017, 03:01:58 PM »
It sounds like an error in your .filetool.lst file.  Show it here.

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Having trouble with Reboot and Backup
« Reply #10 on: April 05, 2017, 03:06:24 PM »
Ok, here is the .filetool.lst file:

Code: [Select]
opt
home
etc/passwd
etc/shadow
etc/sudoers
usr/bin/exittc
usr/bin/exittc.orig
usr/local/etc/samba/smb.conf
usr/local/apache2/htdocs
usr/local/apache2/conf/httpd.conf

Thanks for having a look. I know I'm lost at this point.

BKM

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Having trouble with Reboot and Backup
« Reply #11 on: April 05, 2017, 03:12:08 PM »
And here is a look at the /home/tc/searchfiles directory that holds the old files. This is the one that gets backed up along with home

Code: [Select]
total 1120
drwxrwxrwx    2 tc       staff           80 Apr  5 18:03 .
drwxr-s---    7 tc       staff          300 Apr  5 18:03 ..
-rwxr--r--    1 tc       staff       571652 Apr  5 13:14 TempOutput1.csv
-rwxr--r--    1 tc       staff       571652 Apr  5 13:14 TempOutput2.csv


Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Having trouble with Reboot and Backup
« Reply #12 on: April 06, 2017, 08:01:35 AM »
Ok Rich...

For whatever reason your solution no longer works. No matter what I place in the exittc script, it doesn't execute anything.

After looking back at the commands I place in the exittc script at the beginning, I missed an important clue.
The first two commands were:

rm -rf /home/tc/searchfiles/*

cp -rf /tmp/csvfiles/* /home/TC/searchfiles/

So, one would think that even if the "rm" command didn't work for some reason, the "cp" command would have at least copied the new files into the same directory. This would mean that there would be additional files there the next time we looked. Continuing on thru the rest of the script, the next command we get to is:

sudo /usr/bin/filetool.sh -b

This should have run the backup. If the backup had actually run, then the new files copied into the /home/tc/searchfiles folder would have been preserved on the reboot. And finally we get to the last command in the script:

sudo /usr/bin/exittc.orig

This is the renamed exittc bin file that would normally run before we renamed it and set up the script. On the surface it would appear that this is the only command from the script that actually worked. But that is where we were wrong!!!

To be sure ANYTHING was happening with the exittc script I went back and modified the last command to this:

# sudo /usr/bin/exittc.orig

Thus effectively commenting out the command and preventing it from running at all "IF" the script was working. So one would expect the rest of the reboot/backup to fail with some sort of error. Well, the system did exactly what it had done with every other test scenario I had been attempting. The results were exactly the same.

- The files in the /home/tc/searchfiles folder were left untouched

- The files from the temporary directory /tmp/csvfiles were never copied to the /home/tc/searchfiles directory and they were lost on reboot

- The system appeared to work as if the exittc script never existed.

Ok, so I am completely lost at this point. I can find no reason for the script to fail unless something has changed in how TCL handles the reboot and backup routines that we are not aware of at this time. I do not believe the script was ever executed even though it has the chmod settings you recommended.

- I have tried setting the onwer, group and permissions everywhere to make sure there were no conflicts
- have even tried taking the backed up folder out of the tc user directory and placing it in the root and changing everything for that to be the new destination. The result is still the same.

At this point it "appears" that the exittc script never executes and the renamed exittc.orig also never executes (because I commented it out).

Any other ideas?  I am stumped.

BKM

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: Having trouble with Reboot and Backup
« Reply #13 on: April 06, 2017, 08:50:30 AM »
Code: [Select]
$ which exittc
/usr/local/bin/exittc
Download a copy and keep it handy: Core book ;)

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Having trouble with Reboot and Backup
« Reply #14 on: April 06, 2017, 09:20:45 AM »
Is your news exittc executible ?
ls -l /usr/local/bin/exittc