*New 11.3 series Release:
2019-10-19: XigmaNAS 11.3.0.4.7014 - released

*New 12.0 series Release:
2019-10-05: XigmaNAS 12.0.0.4.6928 - released!

*New 11.2 series Release:
2019-09-23: XigmaNAS 11.2.0.4.6881 - released!

We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS costs money. Please consider donating for our project so that we can continue to offer you the best.
We need your support! eg: PAYPAL

[SOLVED] How to automatically copy certain log files to persistent location before server shutdown?

XigmaNAS Scripts and shell tips
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
netware5
experienced User
experienced User
Posts: 121
Joined: 31 Jan 2017 21:39
Location: Sofia, BULGARIA
Status: Offline

[SOLVED] How to automatically copy certain log files to persistent location before server shutdown?

#1

Post by netware5 » 13 Mar 2018 18:58

I would like to automatically save copies of certain log files (syslog, upslog, etc.) on persistent location just before server shutdown. The idea is to run some script as a part of the shutdown sequence. It should run in all cases, i.e. when shutdown is initiated automatically (by UPS in case of power failure, by thermal protection, after FW update, etc.) or when shutdown is initiated manually (by Web GUI, by console command, etc.).

In the Wiki I found only instructions how to do this periodically using cron jobs, but nothing about how to do this when certain conditions are met - in my case when the shutdown sequence started.

Any help will be highly appreciated.
Last edited by netware5 on 11 Jul 2018 15:47, edited 1 time in total.
XigmaNAS 12.0.0.4 - Reticulus (rev.6881) embedded on HP Proliant Microserver Gen8, Xeon E3-1265L, 16 GB ECC, 2x4TB WD Red ZFS Mirror

User avatar
raulfg3
Site Admin
Site Admin
Posts: 4925
Joined: 22 Jun 2012 22:13
Location: Madrid (ESPAÑA)
Contact:
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#2

Post by raulfg3 » 13 Mar 2018 23:08

use clog_logdir variable in System|Advanced|rc.conf like is described on wiki.

https://nas4free.org/wiki/faq/0046?s[]=move&s[]=log
12.0.0.4 (revision 6766)+OBI on SUPERMICRO X8SIL-F 8GB of ECC RAM, 12x3TB disk in 3 vdev in RaidZ1 = 32TB Raw size only 22TB usable

Wiki
Last changes

netware5
experienced User
experienced User
Posts: 121
Joined: 31 Jan 2017 21:39
Location: Sofia, BULGARIA
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#3

Post by netware5 » 14 Mar 2018 00:01

raulfg3 wrote:
13 Mar 2018 23:08
use clog_logdir variable in System|Advanced|rc.conf like is described on wiki.

https://nas4free.org/wiki/faq/0046?s[]=move&s[]=log
I know how to change log files location, but this is not I am looking for. I want that log files are created and used in their default location "/var/log". Then I want to save them during each shutdown sequence.
XigmaNAS 12.0.0.4 - Reticulus (rev.6881) embedded on HP Proliant Microserver Gen8, Xeon E3-1265L, 16 GB ECC, 2x4TB WD Red ZFS Mirror

User avatar
ms49434
Developer
Developer
Posts: 720
Joined: 03 Sep 2015 18:49
Location: Neuenkirchen-Vörden, Germany - GMT+1
Contact:
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#4

Post by ms49434 » 14 Mar 2018 00:56

Did you look into System > Advanced > Command Scripts?
You can define scripts with type 'shutdown'.
1) XigmaNAS 12.0.0.4 amd64-embedded on a Dell T20 running in a VM on ESXi 6.7U2, 22GB out of 32GB ECC RAM, LSI 9300-8i IT mode in passthrough mode. Pool 1: 2x HGST 10TB, mirrored, SLOG: Samsung 850 Pro, L2ARC: Samsung 850 Pro, Pool 2: 1x Samsung 860 EVO 1TB , services: Samba AD, CIFS/SMB, ftp, ctld, rsync, syncthing, zfs snapshots.
2) XigmaNAS 12.0.0.4 amd64-embedded on a Dell T20 running in a VM on ESXi 6.7U2, 8GB out of 32GB ECC RAM, IBM M1215 crossflashed, IT mode, passthrough mode, 2x HGST 10TB , services: rsync.

netware5
experienced User
experienced User
Posts: 121
Joined: 31 Jan 2017 21:39
Location: Sofia, BULGARIA
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#5

Post by netware5 » 14 Mar 2018 09:10

ms49434 wrote:
14 Mar 2018 00:56
Did you look into System > Advanced > Command Scripts?
You can define scripts with type 'shutdown'.
Thank you very much! That is exactly I looked for. Sorry I missed the parameter "type" in command scripts menu. :)

I have only one question:
When exactly scripts of type "shutdown" are executed? I mean before or after zpool unmount? Because I want log files to be copied somewhere in zpool.
XigmaNAS 12.0.0.4 - Reticulus (rev.6881) embedded on HP Proliant Microserver Gen8, Xeon E3-1265L, 16 GB ECC, 2x4TB WD Red ZFS Mirror

User avatar
raulfg3
Site Admin
Site Admin
Posts: 4925
Joined: 22 Jun 2012 22:13
Location: Madrid (ESPAÑA)
Contact:
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#6

Post by raulfg3 » 14 Mar 2018 11:25

I do not understand why to copy on shutdown and not use the permanent location to write the logs directly to it.
12.0.0.4 (revision 6766)+OBI on SUPERMICRO X8SIL-F 8GB of ECC RAM, 12x3TB disk in 3 vdev in RaidZ1 = 32TB Raw size only 22TB usable

Wiki
Last changes

User avatar
ms49434
Developer
Developer
Posts: 720
Joined: 03 Sep 2015 18:49
Location: Neuenkirchen-Vörden, Germany - GMT+1
Contact:
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#7

Post by ms49434 » 14 Mar 2018 11:52

netware5 wrote:
14 Mar 2018 09:10
ms49434 wrote:
14 Mar 2018 00:56
Did you look into System > Advanced > Command Scripts?
You can define scripts with type 'shutdown'.
Thank you very much! That is exactly I looked for. Sorry I missed the parameter "type" in command scripts menu. :)

I have only one question:
When exactly scripts of type "shutdown" are executed? I mean before or after zpool unmount? Because I want log files to be copied somewhere in zpool.
the rc.shutdown script shuts down services in the reverse order they were started. I would expect the execcmd_shutdown script to be executed first because it doesn't depend on a service (execcmd_shutdown processes those scripts defined in the WebGUI).
1) XigmaNAS 12.0.0.4 amd64-embedded on a Dell T20 running in a VM on ESXi 6.7U2, 22GB out of 32GB ECC RAM, LSI 9300-8i IT mode in passthrough mode. Pool 1: 2x HGST 10TB, mirrored, SLOG: Samsung 850 Pro, L2ARC: Samsung 850 Pro, Pool 2: 1x Samsung 860 EVO 1TB , services: Samba AD, CIFS/SMB, ftp, ctld, rsync, syncthing, zfs snapshots.
2) XigmaNAS 12.0.0.4 amd64-embedded on a Dell T20 running in a VM on ESXi 6.7U2, 8GB out of 32GB ECC RAM, IBM M1215 crossflashed, IT mode, passthrough mode, 2x HGST 10TB , services: rsync.

netware5
experienced User
experienced User
Posts: 121
Joined: 31 Jan 2017 21:39
Location: Sofia, BULGARIA
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#8

Post by netware5 » 14 Mar 2018 13:32

ms49434 wrote:
14 Mar 2018 11:52

the rc.shutdown script shuts down services in the reverse order they were started. I would expect the execcmd_shutdown script to be executed first because it doesn't depend on a service (execcmd_shutdown processes those scripts defined in the WebGUI).
Thank you!
XigmaNAS 12.0.0.4 - Reticulus (rev.6881) embedded on HP Proliant Microserver Gen8, Xeon E3-1265L, 16 GB ECC, 2x4TB WD Red ZFS Mirror

netware5
experienced User
experienced User
Posts: 121
Joined: 31 Jan 2017 21:39
Location: Sofia, BULGARIA
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#9

Post by netware5 » 14 Mar 2018 13:44

raulfg3 wrote:
14 Mar 2018 11:25
I do not understand why to copy on shutdown and not use the permanent location to write the logs directly to it.
My server is in my bedroom. I would prefer to minimize constant HDD I/O operations as I am hearing HDD activities. So I prefer logging in RAM as it is by default. Especially UPS log is annoying as the NUT writes regularly there even when no other activity is present. And I want to preserve the UPS log in particular in order to keep track on power failures. The problem is that in 80% of cases the power failure affect not only my flat but also my ISP equipment outside of my flat (my router is powered by the UPS until its battery dies). In such case my internet connection is also lost and Nas4Free is not able to send me a notification e-mail, so I have no information about when and how long the power failure happened. I need copies of old log files to keep track.
XigmaNAS 12.0.0.4 - Reticulus (rev.6881) embedded on HP Proliant Microserver Gen8, Xeon E3-1265L, 16 GB ECC, 2x4TB WD Red ZFS Mirror

netware5
experienced User
experienced User
Posts: 121
Joined: 31 Jan 2017 21:39
Location: Sofia, BULGARIA
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#10

Post by netware5 » 14 Mar 2018 18:38

In System > Advanced > Command Scripts I've created a type "shutdown" script with the following command:

cp /var/log/system.log /mnt/PendgyNASZpool/Pendgy/Archive/HP\ Microserver/Nas4Free/Logs/.

The command works fine if I type it in the ssh terminal, but during shutdown it fails with error the Microserver/Nas4Free/Logs/. is not a directory. I suppose that the problem is with the name of the directory. It seems to be that it does not understand the space in the directory name, which I typed as it should be (using a backslash followed by space). Why it works in the terminal, but not as a shutdown script?
XigmaNAS 12.0.0.4 - Reticulus (rev.6881) embedded on HP Proliant Microserver Gen8, Xeon E3-1265L, 16 GB ECC, 2x4TB WD Red ZFS Mirror

User avatar
ms49434
Developer
Developer
Posts: 720
Joined: 03 Sep 2015 18:49
Location: Neuenkirchen-Vörden, Germany - GMT+1
Contact:
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#11

Post by ms49434 » 14 Mar 2018 19:00

did you try

cp /var/log/system.log "/mnt/PendgyNASZpool/Pendgy/Archive/HP Microserver/Nas4Free/Logs/."

?
1) XigmaNAS 12.0.0.4 amd64-embedded on a Dell T20 running in a VM on ESXi 6.7U2, 22GB out of 32GB ECC RAM, LSI 9300-8i IT mode in passthrough mode. Pool 1: 2x HGST 10TB, mirrored, SLOG: Samsung 850 Pro, L2ARC: Samsung 850 Pro, Pool 2: 1x Samsung 860 EVO 1TB , services: Samba AD, CIFS/SMB, ftp, ctld, rsync, syncthing, zfs snapshots.
2) XigmaNAS 12.0.0.4 amd64-embedded on a Dell T20 running in a VM on ESXi 6.7U2, 8GB out of 32GB ECC RAM, IBM M1215 crossflashed, IT mode, passthrough mode, 2x HGST 10TB , services: rsync.

netware5
experienced User
experienced User
Posts: 121
Joined: 31 Jan 2017 21:39
Location: Sofia, BULGARIA
Status: Offline

Re: How to automatically copy certain log files to persistent location before server shutdown?

#12

Post by netware5 » 14 Mar 2018 19:28

ms49434 wrote:
14 Mar 2018 19:00
did you try

cp /var/log/system.log "/mnt/PendgyNASZpool/Pendgy/Archive/HP Microserver/Nas4Free/Logs/."

?
Thank you! Now it works!
XigmaNAS 12.0.0.4 - Reticulus (rev.6881) embedded on HP Proliant Microserver Gen8, Xeon E3-1265L, 16 GB ECC, 2x4TB WD Red ZFS Mirror

Post Reply

Return to “Scripts and shell tips”