Mycos应用脚本

一、Linux数据库(Mongodb)按照日期进行数据库文件备份:
mkdir /mycos/mongodb/backup/$(date +%Y%m%d)/ && cp /mycos/mongodb/Survey.* /mycos/mongodb/backup/$(date +%Y%m%d)/

二、Mongodb从一个服务器的实例上复制某个Collection的执行语句
db.runCommand({cloneCollection : "Survey.DataInfo", from : "172.16.19.48:27017", query : {}})

三、Mongodb从一个服务器上复制整个数据库的执行语句db.copyDatabase("Survey","Survey_1","localhost:27017");

四、数据库备份命令:mongodump -h 127.0.0.1:27017 -d Survey -o D:\MongoDB\db_back

五、数据库恢复命令:mongorestore -h 172.16.19.58:27017 -d Surveytest --directoryperdb D:\MongoDB\db_back\Survey (和上面的备份命令配合使用)

六、数据库删除某个字段:先打开数据集合,然后执行相应的命令(eq:db.TaskItem.update({},{$unset: {Years:1}},false,true))

七、mongo加载外部js脚本的命令:mongo localhost:27017/Survey --shell mongo_test.js

     脚本示例:
function date2timestamp(date) { return Math.floor(date.getTime() / 1000); }
function now2timestamp() {
    return date2timestamp(new Date());
}
var progress_update_counts = 100;
var progress_update_seconds = 3;

function createProgress(total) {
    return {
        start: now2timestamp(),
        timer: now2timestamp(),
        total: total,
        count: 0,
        pass: function() {
            if ((++this.count % progress_update_counts == 0) && (now2timestamp() - this.timer > progress_update_seconds)) {
                print("\t" + this.count + ' / ' + this.total + "\t" + (this.count / this.total * 100).toFixed(2) + '%');
                this.timer = now2timestamp();
            }
        },
        done: function() {
            print("\t" + this.total + ' / ' + this.total + "\t100%\tCost " + (now2timestamp() - this.start) + ' seconds.');
        }
    };
}
print('scan [ user ] for information...');
var progress = createProgress(db.UserInfo.count());
db.UserInfo.find().forEach(function(doc) {
    progress.pass();
});
progress.done();

八、安装windows Service 的脚本:

%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe  SurveyResultCalc.exe
        Net Start SurveyResultCalc
        sc config SurveyResultCalc start= auto
       

卸载windows Service 的脚本:

%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe  /u  SurveyResultCalc.exe

九、Mongodb删除集合中字段的脚本:

db.College.update({},{$unset: {CollegeCode:1}},false,true) 删除集合College中的字段CollegeCode