Tiny Core Linux
Tiny Core Base => TCB Q&A Forum => Topic started by: bkm on April 05, 2017, 02:55:11 PM
-
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:
#!/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:
# 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
-
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
-
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
-
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
filetool.sh -b
-
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:
#!/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
-
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:
#!/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
-
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
-
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.
-
>:( Now I am lost again.
Here is my latest update to the script:
#!/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
-
It sounds like an error in your .filetool.lst file. Show it here.
-
Ok, here is the .filetool.lst file:
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
-
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
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
-
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
-
$ which exittc
/usr/local/bin/exittc
-
Is your news exittc executible ?
ls -l /usr/local/bin/exittc
-
Umm... I don't know.
According to the instructions by Rich I was supposed to do all of this with the /usr/bin/exittc
So that is where all of my efforts have been.
I didn't know anything about a /usr/local/bin/exittc
Have I been working in the wrong directory?
BKM
-
bkm,
/usr/bin/exittc
and
/usr/local/bin/exittc
are two different files that do different things.
Do not alter the behavior of the one in /usr/bin (which only kills X) but the one in /usr/local/bin (which is the actual GUI exit tool).
-
Well, as Rich has pointed out, he didn't actually tested it.
Always a good idea to check out the files by oneself before messing with them. ;)
-
::)
Thank you Rich, gerald_clark, and Misalf
Lesson Learned... always check everything. Looking at the exittc in /usr/bin reveals it was not the one I was supposed to be altering as Misalf politely point out.
I was already looking for another method to accomplish what I needed to do. I gave up before going back and checking the basics before then asking the "right" question about exittc. :-[
The Reboot/Backup function now works as I had hoped and everything gets preserved properly.
Since I cannot get back to alter the very first post, if a moderator could kindly mark this solved I would be very appreciative.
Thank you all,
BKM
-
Hi bkm
Sorry for the confusion. When I wrote those instructions exittc was part of the base system and located in /usr/bin/. It was
since moved into Xprogs.tcz which is why it is now in /usr/local/bin/. Not sure why a script with the same name was placed
under /usr/bin.