This is a JavaScript script that can be used to transfer logs from your server to N0C Storage.
Consequently, this allows you to save space and avoid cluttering your SSD, while still keeping your logs accessible.
This script can be used as a starting point to create more complex scripts or integrated directly into an application.
In this example, we set up a cron job to run the script twice a day.
N0C Storage is a platform designed to store massive files such as backups, archives and items that do not require a high-performance disk (SSD).
- Node.js application on your server which generates logs
- S3 JavaScript SDK (e.g. minio)
- Dotenv package (e.g. dotenv)
- SSH access to your server Learn more
Note: Replace username
with your server username and myapp
with your application name.
-
SSH into your server or alternatively use N0C Terminal
-
Source the application environment
source /home/username/nodevenv/myapp/20/bin/activate
The command to source the environment may vary depending on the application and the environment name.
You can find the correct command in the application tab.
-
Install the required packages
npm install minio dotenv
If you are using a different S3 SDK, replace
minio
with the correct package name. -
Create a folder for the script
mkdir /home/username/cron-scripts/transfer-logs/
-
Create a new file in the folder
touch /home/username/cron-scripts/transfer-logs/transfer-logs-to-n0c-storage.js
-
Copy the script content from the repository to the file
nano /home/username/cron-scripts/transfer-logs/transfer-logs-to-n0c-storage.js
Paste the content and save the file.
Note: Alternatively, steps 4-6 can be done via N0C's file manager.
-
Create a
.env
file in the same foldertouch /home/username/cron-scripts/transfer-logs/.env
-
Add the following content to the
.env
file, replacing the placeholders with your dataS3_BUCKET=bucketname S3_HOST=hostname S3_PORT=port S3_ACCESS_KEY=accesskey S3_SECRET_KEY=secretkey S3_SSL=true PATH_TO_LOGS=your-log-path APPLICATION_LOG_FILENAME=your-log-filename ERROR_LOG_FILENAME=your-error-log-filename N0C_STORAGE_LOG_PATH=your-n0c-storage-path
-
Create the cron job via the interface
In the command field, add the following command:
source /home/username/nodevenv/myapp/20/bin/activate && node /home/username/cron-scripts/transfer-logs/transfer-logs-to-n0c-storage.js
To run the script twice a day, select twice a day in the common parameters field
Done! Your logs will now be transferred to N0C Storage twice a day.
To run the script manually: