This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation. |
Difference between revisions of "Linux commands"
From Group-Office Groupware and CRM Documentation
(→Bash Script to migrate a linux system to a fresh system) |
(→Bash Script to migrate a linux system to a fresh system) |
||
Line 54: | Line 54: | ||
MIGRATEUSERS=1 | MIGRATEUSERS=1 | ||
− | #Adjust | + | #Adjust sources to transfer |
− | SOURCES="/etc/ssh/ssh_host_dsa_key.pub /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key.pub /root/passwd.mig /root/shadow.mig /root/group.mig /quota.user /quota.group /home/ /var/www/ /var/lib/mysql/ /vmail/ /usr/share/groupoffice/ /usr/share/www/ /usr/local/kringloopplanner/ /etc/postfix/ /etc/dovecot/ /etc/apache2/ /etc/groupoffice/ /etc/mailname" | + | SOURCES="/etc/ssh/ssh_host_dsa_key.pub /etc/ssh/ssh_host_dsa_key \ |
+ | /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key.pub \ | ||
+ | /root/passwd.mig /root/shadow.mig /root/group.mig /quota.user \ | ||
+ | /quota.group /home/ /var/www/ /var/lib/mysql/ /vmail/ \ | ||
+ | /usr/share/groupoffice/ /usr/share/www/ \ | ||
+ | /usr/local/kringloopplanner/ /etc/postfix/ /etc/dovecot/ \ | ||
+ | /etc/apache2/ /etc/groupoffice/ /etc/mailname" | ||
export UGIDLIMIT=500 | export UGIDLIMIT=500 |
Revision as of 07:25, 12 August 2011
Contents
- 1 restore from backup with rsync
- 2 Find all symbolic links to a specific directory
- 3 Remove all .svn directories except for the actual theme dirs
- 4 Migrate maildirs from Courier to Dovecot
- 5 Bulk rename files
- 6 Copy a large amount of data to another server
- 7 Bash Script to migrate a linux system to a fresh system
restore from backup with rsync
rsync -navu foldertorestore user@domain.com:/path/to/parent/of/foldertorestore
-n is to test
Find all symbolic links to a specific directory
find -maxdepth 4 -type l -exec stat {} \; | grep /usr/local/trunk
Remove all .svn directories except for the actual theme dirs
find ! -path "*/ThemeName/*" -name .svn -type d -exec rm -Rf {} \;
Migrate maildirs from Courier to Dovecot
Got courier-dovecot-migrate.pl from http://wiki.dovecot.org/Migration/Courier
Old structure of maildirs was domain/user/.maildir I needed to convert that to domain/user with the script below
#!/bin/bash ./courier-dovecot-migrate.pl --to-dovecot --recursive --convert domaindirectory for f in `find -name .maildir`; do PARENT=`dirname $f` mv $f/* $f/.[^.]* $PARENT done
Bulk rename files
Rename all en. to et. in files down the tree with find:
find -type f -exec rename -v -n 's/en\./et\./' {} \;
source: http://tips.webdesign10.com/how-to-bulk-rename-files-in-linux-in-the-terminal
Copy a large amount of data to another server
This is faster then rsync because it doesn't do any file analysis:
tar cf - filesORdir | ssh HOSTorIP "(cd /where/to/copy; tar xf -)"
Bash Script to migrate a linux system to a fresh system
#!/bin/bash TARGET=root@freshHostNameOrIP #Set to true to migrate the users above uid 500 MIGRATEUSERS=1 #Adjust sources to transfer SOURCES="/etc/ssh/ssh_host_dsa_key.pub /etc/ssh/ssh_host_dsa_key \ /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key.pub \ /root/passwd.mig /root/shadow.mig /root/group.mig /quota.user \ /quota.group /home/ /var/www/ /var/lib/mysql/ /vmail/ \ /usr/share/groupoffice/ /usr/share/www/ \ /usr/local/kringloopplanner/ /etc/postfix/ /etc/dovecot/ \ /etc/apache2/ /etc/groupoffice/ /etc/mailname" export UGIDLIMIT=500 awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/passwd.mig awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/group.mig awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/shadow.mig for source in $SOURCES; do #-H is very important to preserve hard links! rsync -vaH -e "ssh -i /root/.ssh/id_rsa" $source $TARGET:$source done if [ $MIGRATEUSERS -eq 1 ]; then ssh -i /root/.ssh/id_rsa $TARGET "cat /root/passwd.mig >> /etc/passwd" ssh -i /root/.ssh/id_rsa $TARGET "cat /root/shadow.mig >> /etc/shadow" ssh -i /root/.ssh/id_rsa $TARGET "cat /root/group.mig >> /etc/group" fi