Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Usage: ./Rsync-Unattended.sh /path/to/source/ /path/to/destination YourSecurePassword
- # Source & destination directories, & encryption password.
- source="$1"
- destination="$2"
- password="$3"
- # Get the current system time in the MM-DD-YY-HH-MM-SS (12-hour) format
- timestamp=$(date +%m-%d-%y-%I-%M-%S)
- # Create new directory in destination titled current date/time
- new_dir="$destination/$timestamp"
- mkdir "$new_dir"
- # Create text file to store the rsync output
- touch "$new_dir/rsync_output_$timestamp.txt"
- # Iterate through each item in the source path
- for item in "$source"/*; do
- # Check if the item is a directory
- if [ -d "$item" ]; then
- # Run rsync archive, verbose, progress, and compress. Outputs readout to console and rsync_output_$timestamp.txt.
- rsync -avzP --delay-updates "$item" "$new_dir" | tee -a "$new_dir/rsync_output_$timestamp.txt"
- fi
- done
- # Encrypt $new_dir using 7z with
- 7z a -r -mhe=on -p "$password" "$destination/${timestamp}.7z" "$new_dir" | tee "$destination/7z_output_$timestamp.txt"
- # Check if the tar command was successful
- if [ $? -eq 0 ]; then
- # The tar command was successful, so delete the unarchived data from the destination directory
- rm -r "$new_dir"
- fi
Advertisement
Add Comment
Please, Sign In to add comment