Guest User

Rsync-Unattended.sh

a guest
Jan 7th, 2023
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Usage: ./Rsync-Unattended.sh /path/to/source/ /path/to/destination YourSecurePassword
  4.  
  5. # Source & destination directories, & encryption password.
  6. source="$1"
  7. destination="$2"
  8. password="$3"
  9.  
  10. # Get the current system time in the MM-DD-YY-HH-MM-SS (12-hour) format
  11. timestamp=$(date +%m-%d-%y-%I-%M-%S)
  12.  
  13. # Create new directory in destination titled current date/time
  14. new_dir="$destination/$timestamp"
  15. mkdir "$new_dir"
  16.  
  17. # Create text file to store the rsync output
  18. touch "$new_dir/rsync_output_$timestamp.txt"
  19.  
  20. # Iterate through each item in the source path
  21. for item in "$source"/*; do
  22. # Check if the item is a directory
  23. if [ -d "$item" ]; then
  24. # Run rsync archive, verbose, progress, and compress. Outputs readout to console and rsync_output_$timestamp.txt.
  25. rsync -avzP --delay-updates "$item" "$new_dir" | tee -a "$new_dir/rsync_output_$timestamp.txt"
  26.  
  27. fi
  28. done
  29.  
  30. # Encrypt $new_dir using 7z with
  31. 7z a -r -mhe=on -p "$password" "$destination/${timestamp}.7z" "$new_dir" | tee "$destination/7z_output_$timestamp.txt"
  32.  
  33. # Check if the tar command was successful
  34. if [ $? -eq 0 ]; then
  35. # The tar command was successful, so delete the unarchived data from the destination directory
  36. rm -r "$new_dir"
  37. fi
  38.  
Advertisement
Add Comment
Please, Sign In to add comment