Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/bash
- #move mail files older than 6 month(180 days) of domains to /mnt/mailsback/
- backup_email_folder(){
- d=$1
- folder=$2
- days=$3
- ddest="/mnt/mailsback/$d"
- echo "making dir $ddest"
- exit 1
- [ -d "$ddest" ] || mkdir "$ddest"
- dpath="/usr2/mail/$d"
- email_adds=`ls $dpath`
- for email in $email_adds; do
- echo -e "\n+++++++working on Email: $email+++++ \n" ; sleep 5
- search_fp="$dpath/$email/$folder"
- if [ ! -d "$search_fp" ]; then echo "dir $search_fp does not exist, skip"; continue; fi
- find $search_fp -mtime +${days} | while read f; do
- if [ ! -f "$f" ]; then echo "no files older than 1 months found, skip"; continue; fi
- dest_folder=$ddest/$email/$folder
- echo "making directory: $dest_folder"
- [ -d "$dest_folder" ] || mkdir -p "$dest_folder"
- fd=`ls -lh $f`; printf "\n MOVING: $fd \n"
- mv -v "$f" "$dest_folder"
- done
- done
- echo "####======AM DONE WITH $d DOMAIN=======###"
- }
- backup_domain_emails(){
- domain=$1
- days =$2
- searchp_read="Maildir/cur"
- searchp_unread="Maildir/new"
- searchp_sent="Maildir/.Sent/cur"
- email_folders=($searchp_read $searchp_unread $searchp_sent)
- for folder in ${email_folders[@]}; do
- backup_email_folder $domain $folder $days
- done
- }
- loop_domains(){
- domains_f=$1
- days=$2
- #loop thru file with domains to backup
- while read domain; do
- echo -e "\n====working on domain $domain ========\n"
- continue
- backup_domain_emails $domain $days
- done < $domains_f
- }
- if [ $# -eq 0 ]; then
- echo "No arguments provided"
- echo "provide dir path where domain emails files are"
- exit 1
- fi
- given_p=$1
- days=$2
- if [ -f "$given_p" ]; then
- loop_domains $given_p $2
- else
- backup_domain_emails $given_p $days
- fi
- echo -e "\n #################Am done migrating the domain emails #################\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement