backup_semanal_de_particion_comprimida_y_notificacion_por_email
This is an old revision of the document!
crontab weekly
#!/bin/bash echo "New log file..." > /home/facundo/log.txt echo "#############################" >> /home/facundo/log.txt date >> /home/facundo/log.txt echo "#############################" >> /home/facundo/log.txt echo "Processing........................................" >> /home/facundo/log.txt echo "Deleting files older than a month in dst folder..." >> /home/facundo/log.txt find /mnt/hdd/backups/rberrypart/ -mtime +30 -delete echo "done" >> /home/facundo/log.txt echo "Moving the last backups to retention folder......." >> /home/facundo/log.txt mv /mnt/hdd/backups/rberrypart/latest/PiOS.img.gz /mnt/hdd/backups/rberrypart/PiOS.img.gz_$(date +"%Y%m%d-%H%M%S") mv /mnt/hdd/backups/rberrypart/latest/bootpart.img.gz /mnt/hdd/backups/rberrypart/bootpart.img.gz_$(date +"%Y%m%d-%H%M%S") echo "done" >> /home/facundo/log.txt echo "#############################" >> /home/facundo/log.txt date >> /home/facundo/log.txt echo "#############################" >> /home/facundo/log.txt echo "dding and gzipping /dev/sda1 using the default options" >> /home/facundo/log.txt echo "-----------------------------" >> /home/facundo/log.txt dd bs=4M if=/dev/sda1 2>>/home/facundo/log.txt | gzip --fast > /mnt/hdd/backups/rberrypart/latest/PiOS.img.gz echo "done" >> /home/facundo/log.txt echo "-----------------------------" >> /home/facundo/log.txt echo "" >> /home/facundo/log.txt echo "now dding and --fast gzipping the boot part......." >> /home/facundo/log.txt echo "#############################" >> /home/facundo/log.txt date >> /home/facundo/log.txt echo "#############################" >> /home/facundo/log.txt echo "Processing /dev/mmcblk0p1 ................" >> /home/facundo/log.txt echo "-----------------------------" >> /home/facundo/log.txt dd bs=4M if=/dev/mmcblk0p1 2>>/home/facundo/log.txt | gzip --fast > /mnt/hdd/backups/rberrypart/latest/bootpart.img.gz echo "Finished, all done." >> /home/facundo/log.txt echo "#############################" >> /home/facundo/log.txt date >> /home/facundo/log.txt echo "#############################" >> /home/facundo/log.txt echo "Now sending the status log................" >> /home/facundo/log.txt mutt -s "Weekly Backup Status" facundo.ipharraguerre@pm.me < /home/facundo/log.txt
tal vez se pueda formatear en html
Como poder, se puede pasar a HTML, pero preferible enviarlo en texto plano…
- partbackup.sh
#!/bin/bash LOG_FILE="/home/facundo/log.txt" BACKUP_DIR="/mnt/hdd/backups/rberrypart" DATE="$(date +"%Y%m%d-%H%M%S")" echo "New log file..." > "$LOG_FILE" echo "$(date)" >> "$LOG_FILE" echo "" >> "$LOG_FILE" echo "Files right now in the destination directory:" >> "$LOG_FILE" ls -ltah "$BACKUP_DIR" | awk '{print $5, $9}' >> "$LOG_FILE" echo "" >> "$LOG_FILE" echo "Deleting files older than 2 weeks in destination folder..." >> "$LOG_FILE" find "$BACKUP_DIR" -mtime +13 -delete echo "Done" >> "$LOG_FILE" echo "" >> "$LOG_FILE" echo "Moving the last backups to retention folder:" >> "$LOG_FILE" mv "$BACKUP_DIR/latest/PiOS.img.gz" "$BACKUP_DIR/PiOS.img.gz_$DATE" mv "$BACKUP_DIR/latest/bootpart.img.gz" "$BACKUP_DIR/bootpart.img.gz_$DATE" echo "Done" >> "$LOG_FILE" echo "" >> "$LOG_FILE" echo "Backing up /dev/sda1:" >> "$LOG_FILE" dd bs=4M if=/dev/sda1 2>> "$LOG_FILE" | gzip --fast > "$BACKUP_DIR/latest/PiOS.img.gz" echo "Done" >> "$LOG_FILE" echo "" >> "$LOG_FILE" echo "Backing up /dev/mmcblk0p1 (the boot partition):" >> "$LOG_FILE" dd bs=4M if=/dev/mmcblk0p1 2>> "$LOG_FILE" | gzip --fast > "$BACKUP_DIR/latest/bootpart.img.gz" echo "Finished, all done." >> "$LOG_FILE" echo "Files in the destination directory:" >> "$LOG_FILE" ls -ltah "$BACKUP_DIR" | awk '{print $5, $9}' >> "$LOG_FILE" echo "" >> "$LOG_FILE" echo "Now sending the status log." >> "$LOG_FILE" echo "" >> "$LOG_FILE" mutt -s "Weekly Backup Status" facundo@ad.facundoitest.space < "$LOG_FILE"
backup_semanal_de_particion_comprimida_y_notificacion_por_email.1705283770.txt.gz · Last modified: 2024/10/17 21:42 (external edit)
