Aller au contenu
  • 0

PB sauvegarde Hybride Backup


Invité

Question

Bonjour,

Je vous expose mon soucis, je souhaite externaliser des données stocké sur mon nas vers des disques dur ext USB,
les jobs de sauvegardes sont réalisé deux fois par semaines sur deux disques différents.
il y a donc deux job en place, un le mercredi et un autre le samedi.

j'ai configuré les jobs avec "1 version conservé" et j'ai essayé egalement "version conservé 5 jours " toujours le meme probleme la semaine d'apres a la sauvegarde suivante cela m'indique un manque de place sur les disques.

taille de la sauvegarde : 3To
taille d'un disque 4To

Lien vers le commentaire
Partager sur d’autres sites

1 réponse à cette question

Messages recommandés

  • 0

J'ai quelque chose à vous proposer pour sauvegarder les différentes configuration volumes et image de docker station car cela ne fonctionne pas via le HBS :

#!/bin/sh

# Define the current date (year, month, and day only)
current_date=$(date +'%Y%m%d')

# Define the backup directory
backup_dir="/share/backup/container_backup"

# Define the log file
log_file="${backup_dir}/script.log"

# Define the number of days to keep backups
days_to_keep=30

# Define application yaml folder 
application_path="/share/MD0_DATA/Container/container-station-data/application"

# Logging function
log() {
    local timestamp=$(date +'%Y-%m-%d %H:%M:%S')
    
    # Check if the script is running in a terminal (tty)
    if [ -t 1 ]; then
        echo "$timestamp - $1" | tee -a "$log_file"
    else
        echo "$timestamp - $1" >> "$log_file"
    fi
}

# Function to stop all Docker containers
stop_all_containers() {
    log "Stopping all Docker containers"
    running_containers=$(docker ps -q)

    if [ -n "$running_containers" ]; then
        docker stop $running_containers >> "$log_file" 2>&1
        log "All running Docker containers have been stopped"
    else
        log "No running Docker containers to stop."
    fi
}
# Function to backup Docker containers
backup_containers() {
    log "Starting the backup of all Docker containers"
    
    for container_id in $(docker ps -a -q)
    do
        local container_name=$(docker inspect --format '{{.Name}}' $container_id | sed 's/^\///')
        local tar_file="${backup_dir}/container_backup_${container_name}_${current_date}.tar"

        # Create a tar archive of each Docker container
        docker export -o "$tar_file" $container_id >> "$log_file" 2>&1
        log "Backup of container $container_name completed to $tar_file"

        # Compress the tar file using bzip2
        bzip2 --best "$tar_file" >> "$log_file" 2>&1
        log "Container tar file compressed to ${tar_file}.bz2"

    done

    log "Backup of all Docker containers completed"
}

# Function to backup Docker images
backup_images() {
    log "Starting the backup of Docker images"
    
    local tar_file="${backup_dir}/images_backup_${current_date}.tar"

    docker save -o "$tar_file" $(docker images -q) >> "$log_file" 2>&1
    log "Docker images have been backed up to $tar_file"

    # Compress the tar file using bzip2
    bzip2 --best "$tar_file" >> "$log_file" 2>&1

    log "Backup of Docker images completed"
}

# Function to backup Docker applications (yaml)
backup_applications() {
    log "Starting the backup of Docker applications (yaml)"
    local tar_file="${backup_dir}/application_backup_${current_date}.tar"

    # Compress the contents of the application directory using bzip2
    tar -cf "$tar_file" -C "$application_path" . >> "$log_file" 2>&1
	bzip2 --best "$tar_file" >> "$log_file" 2>&1
    log "Applications tar file compressed to $compressed_file"

    log "Backup of Docker applications (yaml) completed"
}

# Function to backup Docker volumes
backup_volumes() {
    log "Starting the backup of Docker volumes"
    
    # Iterate through all Docker volumes and backup each one
    for volume_name in $(docker volume ls --quiet)
    do
        local tar_file="${backup_dir}/volume_backup_${volume_name}_${current_date}.tar"
        log "Backing up Docker volume $volume_name to $tar_file"

        # Create a tar archive directly
        tar -cf $tar_file -C $(docker volume inspect --format '{{.Mountpoint}}' $volume_name) . >> "$log_file" 2>&1
		bzip2 --best "$tar_file" >> "$log_file" 2>&1
    done

    log "Backup of Docker volumes completed"
}

# Function to start all previously stopped Docker containers
start_all_containers() {
    log "Starting previously stopped containers"
    
    if [ -n "$running_containers" ]; then
        docker start $running_containers >> "$log_file" 2>&1
        log "All previously stopped Docker containers have been started."
    else
        log "No previously stopped Docker containers to start."
    fi
}

# Function to purge duplicate files in the backup directory
purge_duplicates() {
    log "Starting the purge of duplicate files in the backup directory"
    
    # Create a temporary file to store MD5 hashes
    tmpfile=$(mktemp)

    # Use md5sum to calculate MD5 hashes of all files in the directory
    md5sum "${backup_dir}"/* | sort | uniq -d -w 32 > "$tmpfile"

    # Loop through the temporary file to delete duplicate files
    while IFS= read -r line; do
        filepath=$(echo "$line" | cut -d ' ' -f 3-)
        rm "$filepath"
        log "Duplicate file deleted: $filepath"
    done < "$tmpfile"

    # Remove the temporary file
    rm "$tmpfile"
    
    log "Purge of duplicate files in the backup directory completed"
}

# Function to purge old backups
purge_backups() {
    log "Starting the purge of old backups"

    # Exclude script and log files from deletion
    exclude_files="$(basename $0) $(basename $log_file)"

    # Purge backups older than specified days, excluding specified files
    find "$backup_dir" -type f -mtime +$days_to_keep ! -name "$exclude_files" -exec rm {} \;

    log "Purge of old backups completed"
}

# Stop all Docker containers
stop_all_containers

# Backup Docker containers
backup_containers

# Backup Docker images
backup_images

# Backup Docker applications (yaml)
backup_applications

# Backup Docker volumes
backup_volumes

# Start all previously stopped Docker containers
start_all_containers

# Purge duplicate files in the backup directory
purge_duplicates

# Purge old backups
purge_backups

Avec ca je penses qu'on est pas trop mal une fois le script  dans la crontab.

Lien vers le commentaire
Partager sur d’autres sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Invité
Répondre à cette question…

×   Vous avez collé du contenu avec mise en forme.   Supprimer la mise en forme

  Seulement 75 émoticônes maximum sont autorisées.

×   Votre lien a été automatiquement intégré.   Afficher plutôt comme un lien

×   Votre contenu précédent a été rétabli.   Vider l’éditeur

×   Vous ne pouvez pas directement coller des images. Envoyez-les depuis votre ordinateur ou insérez-les depuis une URL.

Chargement
×
×
  • Créer...