Monday, June 17, 2024

Sitecore Custom Audit Logs Generation & move into NoSQL MongoDB Part - 1

 Hi All,

After talking with my senior recently, we came to the conclusion that, while modifications are recorded in Sitecore logs, we do not have access to all audit log details, which presents a common issue across nearly all projects. Because there are so many other entries, it is quite difficult to determine that. In addition, we can store data in SQL, although doing so may eventually cause storage problems due to the database's excessive growth in size, and freetext search is not supported.

Thus, we made the decision to address and attempt to resolve that issue. We separated it into two sections for that:

Part 1: To start, we keep audit logs in a unique folder containing only the audit logs. This way, we can locate all audit-related items in one location and potentially mitigate the problem.

 

Part 2: All custom log data can be transferred to the NoSQL database MongoDB, allowing for cloud storage and more convenient detailed searches for changes to individual items.

I so began my research for Part 1. I broke up my work into the following steps:

 

1. Custom logs must be made in a designated folder.

2. Include audit-related entries.

I really appreciated the blogs listed below during my investigation. Kindly peruse those blogs, as they will offer you a glimpse of my intended actions.

https://www.sitecorefundamentals.com/a-complete-code-sample-for-creating-your-own-custom-sitecore-log

https://sitecore.stackexchange.com/questions/2966/logging-changes-in-sitecore-8-1-made-by-content-authors

I modified it to meet our demands, and the result is our unique code, which is below:

Audit.cs

z.AuditInitial.config

This code functioned as intended and began generating bespoke audit logs after the corresponding dll was deployed into the website bin folder.

However, since our ultimate objective is to store in NoSQL MongoDB rather than txt files, we are aware that it will generate an excessive number of files on disk, potentially leading to a storage problem.

In the next part, we will explain how we can write custom code to move these audit logs to MongoDB.

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.

Sunday, June 9, 2024

Backup website and database via script part-2

Hello everyone,

As I stated in my previous blog post, we can take website and SQL backups more easily if we properly accumulate website and database backup scripts.

We can take it step by step to do this. To start, we make a single batch file that will run the website backup script in addition to the SQL backup. Kindly adjust the settings to suit your particular surroundings.

Make a backup.bat file with the following code in it:


sqlcmd -S ServerName -U sa -P Sitecore@123 -v path = "'C:\Personal\backup\'" -i "website backup.sql"
"C:\Program Files\7-Zip\7z.exe" a -tzip "C:\Personal\backup\DB_%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%.zip" "C:\Personal\backup\sc93local_*.bak"
del "C:\Personal\backup\sc93local_*.bak"

@pause
PowerShell -File "C:\Personal\Tricks\website backup with exclude folder.ps1"

@pause

It will be simpler to identify the backup with a date if you follow the method mentioned above, which generates a backup datewise.

The powershell script that makes a backup of the website is targeted by the lower portion of the batch file.

You can go to this github link for the modified scripts that I changed correctly for the database backup ("website backup.sql") and the website backup ("website backup with exclude folder.ps1").

 

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.