Code Monkey home page Code Monkey logo

truenas-config-backup-script's Introduction

This script is designed to automate the process of creating backups of your TrueNAS configuration and deleting old backups once a specified limit is reached. The script uses environment variables to configure various settings, such as the server URL, API key, backup location, and the maximum number of backup files to keep. Here's a simple explanation of the main components of the script:

Import required libraries: The script imports various libraries needed for its functionality, such as os, subprocess, requests, schedule, time, logging, datetime, and dotenv. Load environment variables: The script uses the dotenv library to load environment variables from a .env file, which contains user-configurable variables like the server URL, API key, secret seed, backup location, maximum number of backup files, and scheduled time for the backup.

Create the backup directory: The script creates a directory for storing backup files using the os.makedirs() function.

Define the backup function: The backup() function is responsible for creating a new backup of the TrueNAS configuration and deleting old backups if the maximum number of backup files is reached. The function does the following: Generates a file name for the backup based on the hostname and the current date and time. Sends a POST request to the TrueNAS API to save the configuration. Writes the configuration data to a file in the backup directory. Checks if there are more backup files than the maximum number allowed and deletes the oldest backup files until the limit is reached.

Schedule the backup function: The script uses the schedule library to schedule the backup() function to run at the specified time every day. Keep the script running: The script continuously runs the scheduled tasks using a while loop, which checks for pending tasks and sleeps for one second between checks. The script is designed to run indefinitely, creating new backups and deleting old ones according to the specified schedule and maximum number of backup files allowed.

truenas-config-backup-script's People

Contributors

regis-loyaute avatar

Stargazers

Subby avatar

Watchers

 avatar

Forkers

senpaisubby

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.