Last active
March 2, 2017 13:58
-
-
Save wezell/20146cfd75b2ea097eb24c5ae414a951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
workFolder=~/fileMigration | |
mkdir -p $workFolder | |
dbFile=$workFolder/db-file.txt | |
webdavUrl=http://demo.dotcms.com/webdav/live/1 | |
creds=admin@dotcms.com:admin | |
sqlCmd="mysql dotcms3 -e \"$sql\"" | |
#sqlCmd="psql -UXXXXXXX dotcms36 -c" | |
delimiter="[\t, \|]" | |
read -r -d '' sql <<- EOM | |
select | |
fvi.identifier, id.parent_path, id.asset_name, con.title | |
from | |
fileasset_version_info fvi, | |
identifier id, | |
contentlet_version_info cvi, | |
contentlet con | |
where | |
fvi.identifier = id.id and | |
id.host_inode = cvi.identifier and | |
fvi.live_inode is not null and | |
cvi.live_inode is not null and | |
cvi.live_inode = con.inode | |
; | |
EOM | |
if [ ! -f $dbFile ]; then | |
eval $sqlCmd > $dbFile | |
fi | |
if [ "$(tail -c1 "$dbFile"; echo x)" != $'\nx' ]; then | |
echo "" >>"$dbFile" | |
fi | |
while read -r line | |
do | |
line=`echo $line | xargs` | |
id=`awk -F "$delimiter" '{print $1}' <<< $line | xargs ` | |
path=`awk -F "$delimiter" '{print $2}' <<< $line | xargs` | |
fileName=`awk -F "$delimiter" '{print $3}' <<< $line | xargs` | |
host=`awk -F "$delimiter" '{print $4}' <<< $line | xargs` | |
if [[ ${#host} -eq 0 || ${#fileName} -eq 0 || ${#path} -eq 0 || $id == "identifier" ]]; then | |
continue | |
fi | |
workingOn=$host$path$fileName | |
cd $workFolder | |
echo "working on: $workingOn" | |
mkdir -p $host$path | |
cd $host$path | |
curl -O --basic --user "$creds" --header "Host:$host" $webdavUrl/$workingOn | |
curl --basic --user "$creds" -X DELETE --header "Host:$host" $webdavUrl/$workingOn | |
done < $dbFile | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Downloads all live legacy files via webdav and archives them on the server.
Once this is done, you will need to login and manually delete the legacy files from the db and flush cache. Then you can drag and drop your downloaded files back into dotCMS via webdav.