Info How to write a remote server shutdown script after checking the shared folder synchronization log table using SQLITE3 built-in synology

Currently reading
Info How to write a remote server shutdown script after checking the shared folder synchronization log table using SQLITE3 built-in synology

2
4
NAS
DS918+
Operating system
  1. macOS
Mobile operating system
  1. iOS
Saves the results of the successful processing of shared folder synchronization to a DB file through the Log Center.

And then we're going to use SQLITE3 built-in synology to re-Script to check.



Once a normal BACKUP has been verified, the remote NAS server can be shut down via the SSH command.



The method is to create a storage destination for archiving settings in Log Center to storage destinations for archive

Select the appropriate folder (in my case, /volume2/log) to download log db files.

Archives local logs to the storage location specified above [V]. Check the and apply it.

스크린샷 2021-06-09 오후 12.48.28.png


This DB file is for SQL LITE, running sqlite3 shown in the command below, and opening the DB file specified above as an archive.

And you can know the result with a query that SELECT count the successful processing of normal synchronization today.



If the value 1 is printed on the r variable, it means that the normal performance is completed, and the backup is only done once a day.

If you have more backups, you should modify the queries and IF conditions in the script below.

In the synology, create a shell script in the shell folder using the vi editor as shown below.



vi /volume2/shell/poweroff_af_sfsync.sh

r=$(sqlite3 /volume2/log/SYNOSYSLOGDB__LOCALARCH.DB "select count(*) as cnt from logs a where host = ‘MAIN NAS' and ldate = date('now','localtime') and prog = 'NetworkBackup' and instr(msg,'Shared Folder Sync finished to sync task') > 0;")
echo $r
if [ $r -eq "0" ] ; then
echo “Shared folder sync error or Not Complete”
else
echo "End backup normally, shutting down BACKUP NAS "
ssh -p 32022 [email protected] sudo "poweroff"
fi


To automatically shut down the remote server with Wish, a copy of the pub key generation via ssh-keygen is required. For this part, please refer to the link below, which is just before the lecture.



The completed script can be registered with the work schedule, given the appropriate frequency, and checked continuously so that the remote server can be shut down if the backup succeeds.


Thank you.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Similar threads

The Indexing Service controls which folders on the NAS are considered as fully accessible for various...
Replies
0
Views
3,502

Welcome to SynoForum.com!

SynoForum.com is an unofficial Synology forum for NAS owners and enthusiasts.

Registration is free, easy and fast!

Trending threads

Back
Top